Here's one approach, using Power Query. This uses a Parameters table to store the folder path (you could of course use VBA to edit this value, if you want to use the folder picker dialog)
There are four queries.
1. fnGetParameter
(ParameterName as text) =>
let
Source = Excel.CurrentWorkbook(){[Name="tbParameters"]}[Content],
Row = Table.SelectRows(Source, each ([Parameter] = ParameterName)),
Value = if Table.IsEmpty(Row) = true
then null
else Record.Field(Row{0},"Value")
in
Value
2. fnDataSheet1
(filepath) =>
let
Source = Excel.Workbook(File.Contents(filepath), null, true),
Sheet = Source{[Item="DataSheet1",Kind="Sheet"]}[Data],
#"Transposed Table" = Table.Transpose(Sheet),
#"Promoted Headers" = Table.PromoteHeaders(#"Transposed Table", [PromoteAllScalars=true])
in
#"Promoted Headers"
3. fnDataSheet2
(filepath) =>
let
Source = Excel.Workbook(File.Contents(filepath), null, true),
Sheet = Source{[Item="DataSheet2",Kind="Sheet"]}[Data]
in
Sheet
4. CombineAllFiles
let
Source = Folder.Files(fnGetParameter("Folder Path")),
#"Merged Columns" = Table.CombineColumns(Source,{"Folder Path", "Name"},Combiner.CombineTextByDelimiter("", QuoteStyle.None),"FilePath"),
#"Removed Other Columns" = Table.SelectColumns(#"Merged Columns",{"FilePath"}),
#"Invoked Custom Function" = Table.AddColumn(#"Removed Other Columns", "Custom1", each fnDataSheet1([FilePath])),
#"Invoked Custom Function1" = Table.AddColumn(#"Invoked Custom Function", "Custom2", each fnDataSheet2([FilePath])),
#"Expanded Custom1" = Table.ExpandTableColumn(#"Invoked Custom Function1", "Custom1", {"Name", "Number", "Data"}, {"Name", "Number", "Data"}),
#"Expanded Custom2" = Table.ExpandTableColumn(#"Expanded Custom1", "Custom2", {"Column1", "Column2", "Column3", "Column4", "Column5"}, {"Column1", "Column2", "Column3", "Column4", "Column5"}),
#"Removed Columns" = Table.RemoveColumns(#"Expanded Custom2",{"FilePath"})
in
#"Removed Columns"
This will combine the data from all files in the folder specified in the parameters table, according to the specification in your first post. Now you can simply "Refresh" the data table, and it will combine the data from all source files.
See attached file for worked example.
Bookmarks