Forum Discussion
Joanne_T_1323
Apr 29, 2023Copper Contributor
Combing workheets into one workboolk
Help please. I have 150 separate worksheets that I need to combine into one document so I can convert to Adobe PDF and upload them to Indesign. Need to stay separate pages, but don't want to have to...
HansVogelaar
Apr 29, 2023MVP
Place all the workbooks that you want to combine in the same folder, without other workbooks.
I'll assume that each workbook has one worksheet (or if it has multiple sheets, that you want the first one).
Run this macro. With 150 workbooks, it'll take a while.
Sub CombineWorkbooks()
Dim strFolder As String
Dim strFile As String
Dim wbkSource As Workbook
Dim wbkTarget As Workbook
With Application.FileDialog(4) ' msoFileDialogFolderPicker
If .Show Then
strFolder = .SelectedItems(1)
Else
Beep
Exit Sub
End If
End With
Application.ScreenUpdating = False
Application.DisplayAlerts = False
Set wbkTarget = Workbooks.Add(Template:=xlWBATWorksheet)
If Right(strFolder, 1) <> "\" Then
strFolder = strFolder & "\"
End If
strFile = Dir(strFolder & "*.xls*")
Do While strFile <> ""
Set wbkSource = Workbooks.Open(Filename:=strFolder & strFile)
wbkSource.Worksheets(1).Copy After:=wbkTarget.Worksheets(wbkTarget.Worksheets.Count)
wbkSource.Close SaveChanges:=False
strFile = Dir
Loop
wbkTarget.Worksheets(1).Delete
Application.DisplayAlerts = True
Application.ScreenUpdating = True
End Sub
- Joanne_T_1323Apr 29, 2023Copper Contributor
HansVogelaar Thanks but I don't understand any of that. I am not familiar with Excel. There was a simple way to combine them that did not include anything like that. As I said, I read it somewhere and it worked, but now I don't remember that I did.
- HansVogelaarApr 29, 2023MVP
I hope that someone else will have a better suggestion for you.