这是我在堆栈溢出时的第一篇文章。我是VBA初学者,所以请接受我为提出愚蠢问题而道歉。我尝试运行以下代码,但是在应该进行复制的第15行,我收到了运行时错误消息“下标超出范围”。谁能帮我吗?非常感谢。
Sub CpyWorksheet()
Dim workbooktarget As Workbook
Dim workbooksource As Workbook
Application.AskToUpdateLinks = False
Application.Calculation = xlCalculationManual
Application.EnableEvents = False
Application.DisplayAlerts = False
Application.ScreenUpdating = False
Set workbooktarget = ThisWorkbook
Set workbooksource = Workbooks.Open("H:\DATA\Workbook\Source Files\Data.xlsx")
workbooksource.Worksheets("Sheet1").Copy After:=workbooktarget.Worksheets("Sheet1")
workbooksource.Close
Application.AskToUpdateLinks = True
Application.Calculation = xlCalculationAutomatic
Application.EnableEvents = True
Application.DisplayAlerts = True
Application.ScreenUpdating = True
End Sub