发布网友 发布时间:2022-04-24 08:56
共2个回答
热心网友 时间:2023-10-09 05:33
这个是代码 第一步新建一个文件夹 皀准备合并的表格文件放在这个文件夹里 然后在这个文件夹李新建一个表格文件 打开 在sheet1处的标签处右键 查看代码 把下面代码复制进去 运行 运行子程序就可以了,如果不行可以把文件 发来我帮你试试
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("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追问能帮我看一下 这个哪里有问题吗?
Dim m As Integer
Dim n As Integer
Dim o As Integer
For m = 2 To 3
n = Sheets(m).[a65536].End(xlUp).Row
o = Sheets(1).[a65536].End(xlUp).Row
Sheets(m).Select
Range("a1", "z" & n).Select
Range("a" & n).Activate
Selection.Copy
Sheets(1).Select
Range("a" & o + 1).Select
ActiveSheet.Paste
Next
热心网友 时间:2023-10-09 05:33
发进我的邮箱