|
本帖最后由 exyantou 于 2019-12-14 09:06 编辑
- Option Explicit
- Sub 汇总表格()
- Dim filename$, sheet_name$, arr_filename(1 To 10 ^ 3) As String
- Dim filecount%, i%, k%
- Dim sh As Worksheet, wb As Object, d As Object, sheetcount_before%
- Dim shapecount%, myshape As Object
- sheetcount_before = ThisWorkbook.Sheets.Count
- filename = Dir(ThisWorkbook.Path & "\*.xl*")
- Do While filename <> ""
- If filename <> ThisWorkbook.Name Then
- filecount = filecount + 1
- arr_filename(filecount) = filename
- filename = Dir
- Else
- filename = ""
- End If
- Loop
- Set d = CreateObject("scripting.dictionary")
- For i = 1 To ThisWorkbook.Sheets.Count
- d(Sheets(i).Name) = ""
- Next i
- Application.ScreenUpdating = False
- Application.DisplayAlerts = False
- For k = 1 To filecount
- sheet_name = Format(Mid(arr_filename(k), InStr(arr_filename(k), ".") - 2, 2), "00")
- If Not d.exists(sheet_name) Then
- Set wb = Workbooks.Open(ThisWorkbook.Path & "" & arr_filename(k))
- wb.Sheets("sheet2").Copy after:=ThisWorkbook.Sheets(ThisWorkbook.Sheets.Count)
- ActiveSheet.Name = sheet_name
- For Each myshape In ActiveSheet.Shapes
- myshape.Delete
- Next myshape
- If ActiveSheet.AutoFilterMode = True Then Rows(2).AutoFilter
- ActiveSheet.Cells.Copy
- ActiveSheet.[a1].PasteSpecial xlPasteValues
- 'ActiveSheet.Cells.Interior.ColorIndex = xlNone
- 'ActiveSheet.Cells.Font.ColorIndex = vbBlack
- wb.Close False
- End If
- Next
- Application.ScreenUpdating = True
- Application.DisplayAlerts = True
- MsgBox "执行完成,本次共更新" & ThisWorkbook.Sheets.Count - sheetcount_before & "个文件", vbInformation
- End Sub
复制代码 试试这个
|
|