Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/excel/23.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/vba/15.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
声明活动工作簿变量Excel Vba_Excel_Vba_Variables - Fatal编程技术网

声明活动工作簿变量Excel Vba

声明活动工作簿变量Excel Vba,excel,vba,variables,Excel,Vba,Variables,(Excel VBA) 如何声明活动工作簿变量。或工作簿变量 我有一个程序在两个excel工作簿之间来回翻动,现在我们只需要重新打开工作簿。但是我可以把它声明为一个变量,这样我就可以引用它而不用重新打开。这会让我的生活轻松很多 提前谢谢 我现在的例子是: Dim xlsMatrixUp As String fileToOpen = Application.GetOpenFilename("Excel Files (*.xls), *.xls") xlsMatrixUp = fileToOpen

(Excel VBA)

如何声明活动工作簿变量。或工作簿变量

我有一个程序在两个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?

然后你可以把它称为wB.worksheets(4)。激活例如

你通常不需要在它们之间切换,只需直接操作范围
这个工作簿。worksheets(4)。range(“A1”).Interior.Color=RGB(128,128,128)
例如,先生,你值得一拍你的后背。非常欢迎。显然,您也可以声明工作表并立即引用它<代码>设置wS=wB.工作表(4)然后直接将其称为
wS.Range(“A1”)
Dim wB as Workbook
Set wB = Workbooks.Open(xlsMatrixUp)