0
Private Sub CommandButton1_Click()
Dim directory As String, fileName As String, sheet As Worksheet, total As Integer
Application.ScreenUpdating = False
Application.DisplayAlerts = False
directory = "c:\Vouchers\"
fileName = Dir(directory & "*.csv??")
Do While fileName <> ""
Workbooks.Open (directory & fileName)
For Each sheet In Workbooks(fileName).Worksheets
total = Workbooks("Voucher Report 26MAR V1.0.xlsm").Worksheets.Count
Workbooks(fileName).Worksheets(sheet.Name).Copy _
after:=Workbooks("Voucher Report 26MAR V1.0.xlsm").Worksheets(total)
Next sheet
Workbooks(fileName).Close
fileName = Dir()
Loop
Application.ScreenUpdating = True
Application.DisplayAlerts = True
End Sub
上面的代碼獲取我需要的所有數據,爲每個工作簿創建一個新的工作表,反正是有從第一個工作簿將數據放置在第10行,然後從添加數據下一個可用行中的下一個工作簿?VBA拉數據關閉的文件
我無法得到Dest的工作,所以我改變它:設置Dest = ThisWorkbook.Sheets.Add(之後:= ThisWorkbook.Sheets(ThisWorkbook.Sheets.Count)) Dest.Name =「My New Sheet」它不會添加一個新聞表,但現在我有複製零件錯誤的問題1004 – Kaz
看起來'.copy'和'.paste'在工作方式上有點不同。檢查更新的代碼 – FreeMan