|
[广告] Excel易用宝 - 提升Excel的操作效率 · Excel / WPS表格插件 ★ 免费下载 ★ ★ 使用帮助★
多文件工作表复制。- Sub ykcbf2() '//2024.1.31 '//多文件
- Dim fns
- Application.ScreenUpdating = False
- Application.DisplayAlerts = False
- Set d = CreateObject("Scripting.Dictionary")
- Set ws = ThisWorkbook
- Set sh = ws.Sheets("操作台")
- For Each sht In Sheets
- If sht.Name <> sh.Name Then sht.Delete
- Next
- p = ThisWorkbook.Path & ""
- With Application.FileDialog(msoFileDialogFilePicker)
- .InitialFileName = p
- .Title = "请选择对应Excel文件"
- .AllowMultiSelect = True
- .Filters.Clear
- .Filters.Add "Excel文件", "*.xls*"
- If .Show Then Set fns = .SelectedItems Else Exit Sub
- End With
- For Each f In fns
- Set wb = Workbooks.Open(f, 0)
- For Each sht In wb.Sheets
- fn = sht.Name
- d(fn) = d(fn) + 1
- sht.Copy after:=ws.Sheets(ws.Sheets.Count)
- ws.Sheets(Sheets.Count).Name = fn & IIf(d(fn) > 1, "(" & d(fn) & ")", "")
- Next
- wb.Close 0
- Next
- sh.Activate
- Application.ScreenUpdating = True
- MsgBox "OK!"
- End Sub
复制代码
|
|