多个excel合并成一个excel表格,且将对应表格文件名合并表格内,对应的位置为各个文件内容第二行的末尾

excel

1个回答

写回答

大大滴阿毛

2026-02-11 07:07

+ 关注

VBA
VBA

VBA代码如下:Sub 文件合并()If Workbooks.Count 1 Then MsgBox 关闭所有工作簿,然后再试!: Exit SubDim fn As String, mPath As String, wb As Workbook, sh As WorksheetDim tt = TimerWith Application.FileDialog(msoFileDialogFolderPicker) .AllowMultiSelect = False .Show If .SelectedItems.Count = 0 Then MsgBox 没有选择任何文件夹! Exit Sub Else mPath = .SelectedItems(1) End IfEnd Withfn = Dir(mPath & *.xls*)Application.ScreenUpdating = FalseDo While fn If fn ThisWorkbook.Name Then k = k + 1 Set wb = Workbooks.Open(mPath & & fn, , True) With wb.Worksheets(1) mary = .Range(A1).CurrentRegion

举报有用(0分享收藏

Copyright © 2025 IZhiDa.com All Rights Reserved.

知答 版权所有 粤ICP备2023042255号