Option Explicit
Sub CombineFiles()
Dim path As String
Dim Filename As String
Dim Wkb As Workbook
Dim ws As Worksheet
Application.EnableEvents = False
Application.ScreenUpdating = False
path = "C:\Users\Abins\Desktop\Payment Posting VBA 19062022\Consol" 'Change as needed
Filename = Dir(path & "\*.xls", vbNormal)
Do Until Filename = ""
Set Wkb = Workbooks.Open(Filename:=path & "\" & Filename)
For Each ws In Wkb.Worksheets
ws.Copy After:=ThisWorkbook.Sheets(ThisWorkbook.Sheets.Count)
Next ws
Wkb.Close False
Filename = Dir()
Loop
Application.EnableEvents = True
Application.ScreenUpdating = True
MsgBox "Success! Press Cntrl+J"
End Sub
我想找到一个解决方案,因为这个代码被用来从一个包含80多个Excel工作簿,每个有三个工作表的文件夹中合并多个文件。它在我的系统上工作正常(在我的个人笔记本电脑,办公系统,和一个同事的系统)。
任何帮助都是感激不尽的
先谢了
1条答案
按热度按时间mzsu5hc01#
导入工作表
On Error Resume Next
,否则该文件夹中似乎没有文件,因为可能存在以下过程中涉及的任何问题。给予尝试一下并分享一些反馈。