0
我有许多单独的Excel工作簿,每个工作表都有一个工作表。我需要将其复制到汇总电子表格中。我尝试了下面的内容,并得到错误9下标超出范围。使用Excel工作簿时出现VBA错误“下标超出范围”。复制
该错误发生在workbooks.copy行。如果我注释掉“after ...”位,它仍然会出现同样的错误,所以它必须是workbooks.copy命令,它会导致错误,但我不明白为什么。任何帮助非常感谢。谢谢。
Sub test()
On Error GoTo testErr
If Len(Dir("z:\September14\Birmingham.xlsx")) <> 0 Then
If Len(Dir("z:\September14\BirminghamSummary.xlsx")) <> 0 Then
Workbooks("z:\September14\birmingham.xlsx").Sheets(1).Copy , _
after:=Workbooks("z:\September14\BirminghamSummary.xlsx").Sheets(1)
End If
End If
Workbooks.Close
Exit Sub
testErr:
MsgBox Err.Number & " : " & Err.Description
End Sub
您需要先打开两个工作簿,然后才能将工作表从一个工作簿复制到另一个工作簿。 – 2014-09-20 12:21:22