0
我一直在將4個excel文件中的「Entry」選項卡定期複製到一個名爲「Data Upload」的新文檔中。將特定工作表複製到新文檔 - Excel VBA
我是VBA的新手,但希望有一種自動化的方式來運行此過程。我已經嘗試使用下面的代碼,但收到
運行時錯誤9下標越界
在此行中:
全碼:
Sub CombineSheets()
Dim sPath As String
Dim sFname As String
Dim wBk As Workbook
Dim wSht As Variant
Application.EnableEvents = False
Application.ScreenUpdating = False
sPath = InputBox("Enter a full path to workbooks")
ChDir sPath
sFname = InputBox("Enter a filename pattern")
sFname = Dir(sPath & "\" & sFname & ".xl*", vbNormal)
wSht = InputBox("Enter a worksheet name to copy")
Do Until sFname = ""
Set wBk = Workbooks.Open(sFname)
Windows(sFname).Activate
Sheets(wSht).Copy Before:=ThisWorkbook.Sheets(1)
wBk.Close False
sFname = Dir()
Loop
ActiveWorkbook.Save
Application.EnableEvents = True
Application.ScreenUpdating = True
End Sub
真的很感激任何意見,哪裏出錯或簡單的例子想辦法做到這一點。
您在哪一行收到此消息? – QHarr
我收到此錯誤在:表(wSht).Copy Before:= ThisWorkbook.Sheets(1) – Spacepope
嘗試'wBk.Sheets(wSht).Copy Before:= ThisWorkbook.Sheets(1)' –