2

(Excel VBA)

我将如何声明一个活动的工作簿变量。或一般的工作簿变量。

我有一个程序在 2 个 excel 工作簿之间来回切换,目前我们只是重新打开该工作簿。但是我可以将它声明为一个变量,这样我就可以在不重新打开的情况下引用它。这会让我的生活轻松很多。

提前致谢!

我目前的例子:

Dim xlsMatrixUp As String
fileToOpen = Application.GetOpenFilename("Excel Files (*.xls), *.xls")
xlsMatrixUp = fileToOpen
Workbooks.Open xlsMatrixUp
ActiveWorkbook.Worksheets(4).Activate 'Grabs matrix file

'Goes back to sheet with macro
ThisWorkbook.Worksheets(4).Activate
    ActiveSheet.range("A1").Interior.Color = RGB(128, 128, 128)
'This is off a working if statement 
Workbooks.Open xlsMatrixUp
ActiveWorkbook.Worksheets(4).Activate`
'Returns to matrix and repeats. Any suggestions?
4

1 回答 1

3
Dim wB as Workbook
Set wB = Workbooks.Open(xlsMatrixUp)

那么您可以将其称为wB.worksheets(4).Activate例如

于 2013-07-11T15:02:55.683 回答