简体   繁体   English

使用VBA将多个工作簿合并到一个(新)主工作簿中

[英]Merge multiple workbooks in one (new) master workbook using VBA

I need some help on integrating multiple workbooks into a single master workbook. 在将多个工作簿集成到单个主工作簿中时,我需要一些帮助。 I am trying to use the following macro code. 我正在尝试使用以下宏代码。 Problem is that it doesn't enter the do while loop. 问题在于它没有进入do while循环。 I have verified the path too. 我也验证了路径。 Kindle help Kindle帮助

Sub GetSheets()
Path = "C:\Users\ssehgal\Documents\Excel-Files-For-Macro"
Filename = Dir(Path & "*.xls")
  Do While Filename <> ""
     Workbooks.Open Filename:=Path & Filename, ReadOnly:=True
     For Each Sheet In ActiveWorkbook.Sheets
        Sheet.Copy After:=ThisWorkbook.Sheets(1)
     Next Sheet
     Workbooks(Filename).Close
     Filename = Dir()
  Loop
End Sub

Replace this: 替换为:

Path = "C:\Users\ssehgal\Documents\Excel-Files-For-Macro"
Filename = Dir(Path & "*.xls")

with this: 有了这个:

Path = "C:\Users\ssehgal\Documents\Excel-Files-For-Macro\"
Filename = Dir(Path & "*.xls")

You were missing the \\ 您错过了\\

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM