我是VBA的新手,正在尝试自动更新工作簿。我有一个源工作簿A和一个目标工作簿B。两者都有一个名为roll out summary的工作表。我希望用户在A中更新此工作表,然后单击更新按钮,该按钮应运行我的宏。此宏应自动更新工作簿B中的工作表而无需打开工作簿B。
我尝试了这段代码,但它不起作用并给出错误:
Dim wkb1 As Workbook
Dim sht1 As Range
Dim wkb2 As Workbook
Dim sht2 As Range
Set wkb1 = ActiveWorkbook
Set wkb2 = Workbooks.Open("B.xlsx")
Set sht1 = wkb1.Worksheets("Roll Out Summary") <Getting error here>
Set sht2 = wkb2.Sheets("Roll Out Summary")
sht1.Cells.Select
Selection.Copy
Windows("B.xlsx").Activate
sht2.Cells.Select
Selection.PasteSpecial Paste:=xlPasteFormulasAndNumberFormats, Operation:= _
xlNone, SkipBlanks:=False, Transpose:=False