|
Sub ºÏ²¢µ±Ç°Ä¿Â¼ÏÂËùÓй¤×÷²¾µÄÈ«²¿¹¤×÷±í()
Dim MyPath, MyName, AWbName
Dim Wb As Workbook, WbN As String, G As Long, Num As Long
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
If Num = 1 Then
Wb.Sheets(1).UsedRange.Copy .Cells(1, 1)
Else
Wb.Sheets(1).UsedRange.Offset(1, 0).Copy .Cells(.Range("A65536").End(xlUp).Row + 1, 1)
End If
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
首先,我不知道从excel复制过来的代码为什么中文变成了乱码,原来的是这样的:
Sub 合并当前目录下所有工作簿的全部工作表()
————————————————————
MsgBox "共合并了" & Num & "个工作薄的工作表。如下:" & Chr(13) & WbN, vbInformation, "提示"
End Sub
代码是从我的印象笔记复制过去的,运行后,合并了许多的工作表,但没法知道是不是全部合并了(统计困难)之后就出现了应用程序错误1004,应用程序未定义或对象未定义的错误,求教啊大神们,是代码有了问题吗
|
|