好友
阅读权限10
听众
最后登录1970-1-1
|
abs
发表于 2019-9-6 08:14
Sub 工作表()
Dim MyPath, MyName, AWbName
Dim Wb As Workbook, WbN As String
Dim G As Long, ShRcou As Long, ShCol As Integer
Dim Num As Long, WbSht 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
For G = 1 To Sheets.Count
WbSht = Replace(Left(MyName, Len(MyName) - 4), ".", "") & ";" & Wb.Sheets(G).Name
If .UsedRange.Count = 1 Then
ShCol = Wb.Sheets(G).UsedRange.Columns.Count
ShRcou = Wb.Sheets(G).UsedRange.Rows.Count
.Cells(1, ShCol + 1) = "合并名称"
.Cells(1, ShCol + 1).Font.Bold = 1
.Cells(.Cells(Rows.Count, 1).End(xlUp).Row + 1, ShCol + 1).Resize(ShRcou - 1) = WbSht
Wb.Sheets(G).UsedRange.Copy .Cells(.Cells(Rows.Count, 1).End(xlUp).Row, 1)
Else
ShRcou = Wb.Sheets(G).UsedRange.Rows.Count
.Cells(.Cells(Rows.Count, 1).End(xlUp).Row + 1, ShCol + 1).Resize(ShRcou - 1) = WbSht
Wb.Sheets(G).Cells(2, 1).Resize(ShRcou, ShCol).Copy .Cells(.Cells(Rows.Count, 1).End(xlUp).Row + 1, 1)
End If
Next
WbN = WbN & Chr(13) & Wb.Name
Wb.Close False
End With
End If
MyName = Dir
Loop
ActiveSheet.UsedRange.Borders.LineStyle = 1
Range("A1").Select
Application.ScreenUpdating = True
End Sub |
|