I want to be able to take x number of files in a folder and put them all on seperate sheets of the same workbook.
I found this code that works;
Public Sub consolWB()
Dim FSO As Object
Dim folder As Object, subfolder As Object
Dim wb As Object
Set FSO = CreateObject("Scripting.FileSystemObject")
folderPath = "C:\Users\patrickw\Desktop\exceltest"
Set folder = FSO.GetFolder(folderPath)
With Application
.DisplayAlerts = False
.ScreenUpdating = False
.EnableEvents = False
.AskToUpdateLinks = False
End With
For Each wb In folder.Files
If Right(wb.Name, 3) = "xls" Or Right(wb.Name, 4) = "xlsx" Or Right(wb.Name, 4) = "xlsm" Then
Set openWB = Workbooks.Open(wb)
For Each ws In openWB.Worksheets
ws.Copy after:=ThisWorkbook.Sheets(ThisWorkbook.Sheets.Count)
Next ws
openWB.Close
End If
Next wb
With Application
.DisplayAlerts = True
.ScreenUpdating = True
.EnableEvents = True
.AskToUpdateLinks = True
End With
End Sub
However, this only works because I have set the target filepath for it to look in.
I want to create a button that prompts the user for a filepath, and then uses that filepath to bring in the files.
I think I have to make the input a string, then use this variable in the code above.
is this possible?
In the example above, the new sheets are just called 'sheet1...' is it possible to name these myself?
Thanks