引用其他工作簿的工作表的正确语法是什么?以下代码在最后一行抛出错误。谢谢!
'Instantiate Workbook variables
Dim mWB As Workbook 'master workbook
'Instantiate Worksheet variables
Dim mWS As Worksheet 'master worksheet
'Open Workbook, set variables and reference range
Workbooks.Open ("Local 500GB HD:Users:user:Public:file.xlsx")
Set mWB = ActiveWorkbook
Set mWS = Sheets("Invoices")
mWB.mWS.Range("A1").FormulaR1C1 = "Import Date" ' <---- This is the where the error is
最佳答案
更改
Set mWS = Sheets("Invoices")
至
Set mWS = mWb.Sheets("Invoices")
然后,在最后一行写
mWS.Range("A1").FormulaR1C1 = "Import Date"
。实际上,由于您的
ActiveWorkbook
不变,因此您可以将最后一行更改为像我在上面放置的那样,但是,最好的做法是完全限定所有变量,因此不会发生意外行为。