如何将多个wpsexcel表格合并为一个表格?
2019-11-14 · 旨在提供办公软件的问答帮助。
1/7
首先将需要合并的excel所有表格存放在同一个文件夹中
2/7
然后再该文件夹中新建一个空白的excel表格
3/7
然后打开新建的excel表格,找到sheet1,然后在sheet1上面鼠标单击右键,点击“查看代码”
4/7
点击“查看代码”后,就会出现下图中的框框,然后在右边框框中填入下列代码:
Sub 合并当前目录下所有工作簿的全部工作表()
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 & "\" & "*.xls")
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("A65536").End(xlUp).Row + 2, 1) = Left(MyName, Len(MyName) - 4)
For G = 1 To Sheets.Count
Wb.Sheets(G).UsedRange.Copy .Cells(.Range("A65536").End(xlUp).Row + 1, 1)
Next
WbN = WbN & Chr(13) & Wb.Name
Wb.Close False
End With
End If
MyName = Dir
Loop
Range("A1").Select
Application.ScreenUpdating = True
MsgBox "共合并了" & Num & "个工作薄下的全部工作表。如下:" & Chr(13) & WbN, vbInformation, "提示"
End Sub
5/7
代码填入好后,如果代码出现红色的,那说明改代码有问题,需要更改,反之正常。
6/7
确定代码无误后,再点击下图中箭头所指的图标或者是按快捷键F5,即可开始excel表格的合并运行
7/7
若结果弹出下面的对话框,这说明合并成功,反之就没有