Create a new blank Excel to store as a merged dataset, and then execute the following code in VBA:
Subunionallexcel () basepath="D:\Work\Temp\ExcelTemplate\" 'Excel folder path, must last add \Subfile =Dir(BasePath, vbdirectory) HeaderRow=2 'number of column header rows (you can set yourself according to how many rows and columns are in the data)Rowno= HeaderRow'result data Start row, first behavior column header Do whileSubfile <>"" IfSubfile <>"." andSubfile <>".." Then SetWB =GetObject(BasePath +subfile)'The default is to merge the first workbook in each ExcelRowsum = wb. Sheets (1). Range ("A65536"). End (Xlup). Row Colsum= WB. Sheets (1). Range ("IV1"). End (xlToLeft). ColumnIfRowno = HeaderRow Then 'Copy Column header row for the first time 'column header contents from cell (first) to cell (headerrow,colsum)Wb. Sheets (1). Range (WB. Sheets (1). Cells (1,1), WB. Sheets (1). Cells (HeaderRow, Colsum)). Copy Range (Cells (1,1), Cells (HeaderRow, colsum))End If 'Copy Content DataWb. Sheets (1). Range (WB. Sheets (1). Cells (HeaderRow +1,1), WB. Sheets (1). Cells (Rowsum, Colsum)). Copy Range (Cells (Rowno +1,1), Cells (Rowno +rowsum, Colsum)) Rowno= Rowno + Rowsum-HeaderRow WB. CloseFalse End IfSubfile=Dir LoopThisworkbook.saveEnd Sub
"Excel&vba" merge Excel files for unified templates