本文介绍了如何使用Excel VBA API在工作簿中获取多个选定的工作表句柄的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
有一种选择多个Excel表单的方法,然后对它们进行一些操作,如打印。然而,给出了一个工作簿,我如何知道选择了哪些工作表。有一个vba属性Application-> ActiveSheet给我们当前的活动表单,但是我找不到任何方式来获得多个表。
There is a way to select multiple Excel sheets and then do some action on them like Print. However given a workbook, how do i get to know which sheets are selected. There is a vba property Application->ActiveSheet which gives us current active sheet, but i couldn't find any way to get multiple sheets for this.
推荐答案
这是你想要的吗?
Option Explicit
Sub Sample()
Dim ws As Worksheet
Dim SelectedSheets() As String
Dim n As Long, i As Long
n = 0
For Each ws In ActiveWindow.SelectedSheets
ReDim Preserve SelectedSheets(n)
SelectedSheets(n) = ws.Name
n = n + 1
Next
For i = LBound(SelectedSheets) To UBound(SelectedSheets)
'~~> This will give you the list of selected sheets
Debug.Print SelectedSheets(i)
Next i
'~~> The collection can also be used as below
'Sheets(SelectedSheets).Copy
'Sheets(SelectedSheets).Select ' e.g., to re-select them later
End Sub
Sid
这篇关于如何使用Excel VBA API在工作簿中获取多个选定的工作表句柄的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!