亲,想制作一个一键生成程序,把EXCEL合并成一个表里?
Private Sub Command1_Click()Dim MyPath, MyName, AWbName
Dim WbN As String
Dim G As Long
Dim Num As Long
Dim BOX As String
Dim EXAPP As Excel.Application
Dim WB As Excel.Workbook
Dim sht As Excel.Worksheet
Set EXAPP = CreateObject("excel.application")
Set WB = EXAPP.Workbooks.Open("d:\gz\汇总2019.xlsx")
'Set WB = Excel.Workbooks.Open(MyPath & "\" & MyName)
Set sht = WB.Worksheets("总表")
Excel.Application.ScreenUpdating = False
MyPath = "D:\gz"
MyName = Dir(MyPath & "\" & "*.xls")
AWbName = "汇总2019"
Num = 0
Do While MyName <> ""
If MyName <> AWbName Then
'Set WB = Excel.Workbooks.Open(MyPath & "\" & MyName)
Num = Num + 1
With Workbooks(1).ActiveSheet.Cells(sht.Range("A65536").End(xlUp).Row + 2, 1) = Left(MyName, Len(MyName) - 4)
For G = 1 To Sheets.Count
WB.Sheets(G).UsedRange.Copy.Cells=(sht.Range("A65536").End(xlUp).Row + 1)1)
WbN = WbN & Chr(13) & WB.Name
WB.Close False
End With
End If
MyName = Dir
Loop
sht.Rows("1:1").Select
sht.Range("A1").Activate
'Range("A1").Select
Application.ScreenUpdating = True
MsgBox "共合并了" & Num & "个工作薄下的全部工作表。如下:" & Chr(13) & WbN, vbInformation, "提示"
EXAPP.Workbooks.Close
EXAPP.Quit
Set EXAPP = Nothing
End Sub
图中红色部门,在运行时,出现红色。请问如何表达这个