我有一个文件,当我打开文件时,我想打开另一个工作表(来自另一个文件)。实际的代码在作为单个命令运行时有效,但是当我尝试将其打开以使其在文件打开时有效
Sub ImportWorksheet()
Sheets("Sheet1").Select
PathName = Range("D3").Value
Filename = Range("D4").Value
TabName = Range("D5").Value
ControlFile = ActiveWorkbook.Name
Workbooks.Open Filename:=PathName & Filename
ActiveSheet.Name = TabName
Sheets(TabName).Copy After:=Workbooks(ControlFile).Sheets(1)
Windows(Filename).Activate
ActiveWorkbook.Close SaveChanges:=False
Windows(ControlFile).Activate
ActiveWorkbook.Sheets("Sprinter-DB").Visible = False
End Sub
运行时错误“ 9”: 下标超出范围 在Windows(Filename).Activate行上