如果我同时处理两本工作簿
例如" 1.xlsb"和" 2。 XLSB"
我在" 1.xlsb"上运行宏。同时我在" 2.xlsb"
in" 1.xlsb"在宏中有一个声明
ThisWorkbook.ActiveSheet
现在的问题是我在运行宏并在" 2.xlsb"中找到另一个工作簿。所以" 1.xlsb"它无法访问ThisWorkBook.ActiveSheet所以我能为此做些什么,所以我也可以在另一个工作簿上工作,宏在另一个工作簿的后台运行
Public Function GetBWTableInActiveSheet() As BoardwalkTable
Dim ws As Worksheet
Dim bwtResult As BoardwalkTable
Set bwtResult = Nothing
Set ws = ThisWorkbook.ActiveSheet
For Each bwtResult In BoardwalkAPI.GetBoardwalkTables
If StrComp(bwtResult.getrange.Parent.name, ws.name, vbTextCompare) = 0 Then
Exit For
End If
Next bwtResult
Set GetBWTableInActiveSheet = bwtResult
Debug.Print bwtResult.getName
End Function
答案 0 :(得分:2)
您可以使用Workbooks("Name of your workbook").Sheets("Name of your sheet")