View Single Post
 
Old 10-23-2018, 11:28 AM
Vivianweir Vivianweir is offline Mac OS X Office 2011 for Mac
Novice
 
Join Date: Oct 2018
Posts: 2
Vivianweir is on a distinguished road
Exclamation Need help fixing compile error expected End Sub to combine multiple documents into one (Mac)

I would like to combine multiple excel files into one. I was referred to trumpexcel.com. I entered the following and get a compile error: expected End Sub. How do I fix it? Is trumpexcel legit? If not what is the right verbiage to use?
Code:
Sub ConslidateWorkbooks()
'Created by Sumit Bansal from https://trumpexcel.com
Dim FolderPath As String
Dim Filename As String
Dim Sheet As Worksheet
Application.ScreenUpdating = False
FolderPath = Environ("userprofile") & "\Desktop\files to merge\"
Filename = Dir(FolderPath & "*.xls*")
Do While Filename <> ""
  Workbooks.Open Filename:=FolderPath & Filename, ReadOnly:=True
  For Each Sheet In ActiveWorkbook.Sheets
    Sheet.Copy After:=ThisWorkbook.Sheets(1)
  Next Sheet
  Workbooks(Filename).Close
  Filename = Dir()
Loop
Application.ScreenUpdating = True
End Sub
Thank you!!!

Last edited by Pecoflyer; 10-24-2018 at 11:19 PM. Reason: Added code tags & repaired formatting (macropod) + added Mac to title
Reply With Quote