【#文档大全网# 导语】以下是®文档大全网的小编为您整理的《excel多个相同格式文档合并到一个工作表中宏代码》,欢迎阅读!
'注意:工作表的名字字符小于13;中英文都可以(最好是英文)
Dim MyPath, MyName, AWbName
Dim Wb As Workbook, WbN As String
Dim G As Long
Dim Num As Long
Dim BOX As String
Application.ScreenUpdating = False
MyPath = ActiveWorkbook.Path
MyName = Dir(MyPath & "\" & "*.xlsx")
AWbName = ActiveWorkbook.Name
Num = 0
Do While MyName <> ""
If MyName <> AWbName Then
Set Wb = Workbooks.Open(MyPath & "\" & MyName)
Num = Num + 1
With Workbooks(1).ActiveSheet
.Cells(.Range("B65536").End(xlUp).Row + 2, 1) = Left(MyName, Len(MyName) - 4)
For G = 1 To Sheets.Count
Wb.Sheets(G).UsedRange.Copy .Cells(.Range("B65536").End(xlUp).Row + 1, 1)
Next
WbN = WbN & Chr(13) & Wb.Name
Wb.Close False
End With
End If
MyName = Dir
Loop
Range("B1").Select
Application.ScreenUpdating = True
MsgBox "共合并了" & Num & "个工作薄下的全部工作表。如下:" & Chr(13) & WbN, vbInformation, "提示"
End Sub
复制上面的内容到:右键一个工作表--查看代码--复制代码后按F5(运行子过程或用户窗体)
如果要不同的excel放到一个excel中分不同工作表:
把需要复制的EXCEL文档打开,在需要复制工作表标签上点右键,选择移动或复制工作表,然后在打开的对话框中选择要移动到的文档(即工作簿)--自己新建一个,然后点确实就行了
本文来源:https://www.wddqxz.cn/af56bb43f02d2af90242a8956bec0975f465a4a7.html