treyabrown
New Member
- Joined
- May 23, 2014
- Messages
- 7
I am trying to figure out how to combine 2 macros. The first macro allows me to select the file path I need, and the second macro will use the file path from the first macro and pull the worksheets from all files in the file path and combine them into 1 summary workbook.
What is the best way to combine the 2 macros, OR call the variable from the first macro?
The first macro:
Sub GetFolder()
Set myFolder = Application.FileDialog(msoFileDialogFolderPicker)
With myFolder
.Title = "Choose Folder"
.AllowMultiSelect = False
If .Show <> -1 Then
Exit Sub
End If
FolderSelected = .SelectedItems(1)
End With
MsgBox "You Selected:" & FolderSelected
End Sub
Second macro:
Sub GetSheets()
Path = "Y:\MC+ Data Dumps" & "\"
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
What is the best way to combine the 2 macros, OR call the variable from the first macro?
The first macro:
Sub GetFolder()
Set myFolder = Application.FileDialog(msoFileDialogFolderPicker)
With myFolder
.Title = "Choose Folder"
.AllowMultiSelect = False
If .Show <> -1 Then
Exit Sub
End If
FolderSelected = .SelectedItems(1)
End With
MsgBox "You Selected:" & FolderSelected
End Sub
Second macro:
Sub GetSheets()
Path = "Y:\MC+ Data Dumps" & "\"
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