I have a task - consolidate various documents (the number of those might differ) from one folder into one master data.
Each document is based on a template so they look exactly the same, each with two sheets, but their names are different.
I need ONLY one of those sheets to be copied, named "Fill this out".
So optimal solution would be: Master data workbook, with as many worksheets as there are files in the folder, and each sheet containing data ONLY from "Fill this out" sheet.
My current code:
Sub MergeWorkbooks()
Dim FolderPath As String
Dim File As String
FolderPath = "C:\Users\" & Environ("username") & "\Downloads\BH\"
File = Dir(FolderPath)
Do While File <> ""
Workbooks.Open FolderPath & File
ActiveWorkbook.Worksheets("Fill this out").Copy _
after:=ThisWorkbook.Worksheets(ThisWorkbook.Worksheets.Count)
ActiveSheet.Name = File
Workbook.Close FolderPath & File
File = Dir()
Loop
End Sub
Copies only first file and then error 400 pops out.
Additionally, the new sheet name is: "Fill this out" in stead of file name.
Please help.