Hi All,
I am trying to loop through files in a folder and Copy the first sheet to a new workbook. I want the first sheet in each file to be it's own worksheet in a master workbook. I managed to figure out the looping part, but am stuck on copying the first sheet to a new workbook. Any help would be greatly appreciated. Thanks!
I am trying to loop through files in a folder and Copy the first sheet to a new workbook. I want the first sheet in each file to be it's own worksheet in a master workbook. I managed to figure out the looping part, but am stuck on copying the first sheet to a new workbook. Any help would be greatly appreciated. Thanks!
Code:
Sub LoopAllExcelFilesInFolder()
Dim wb As Workbook
Dim myPath As String
Dim myFile As String
Dim myExtension As String
Dim FldrPicker As FileDialog
Application.ScreenUpdating = False
Application.EnableEvents = False
Application.Calculation = xlCalculationManual
Set FldrPicker = Application.FileDialog(msoFileDialogFolderPicker)
With FldrPicker
.Title = "Select A Target Folder"
.AllowMultiSelect = False
If .Show <> -1 Then GoTo NextCode
myPath = .SelectedItems(1) & "\"
End With
NextCode:
myPath = myPath
If myPath = "" Then GoTo ResetSettings
myExtension = "*.xls*"
myFile = Dir(myPath & myExtension)
Do While myFile <> ""
Set wb = Workbooks.Open(Filename:=myPath & myFile)
DoEvents
Debug.Print wb.Worksheets(1).Name
DoEvents
myFile = Dir
Loop
MsgBox "Task Complete!"
ResetSettings:
Application.EnableEvents = True
Application.Calculation = xlCalculationAutomatic
Application.ScreenUpdating = True
End Sub