|
请参考:- Sub Macro1()
- Dim Fso As Object, Folder As Object, arr$(), m&, i&, p$, wf As WorksheetFunction
- p = ThisWorkbook.Path
- Set wf = WorksheetFunction
- Set Fso = CreateObject("Scripting.FileSystemObject")
- Set Folder = Fso.GetFolder(p)
- Application.ScreenUpdating = False
- Call GetFiles(Folder, arr, m)
- For i = 1 To m
- With Workbooks.Open(arr(1, i))
- With .Worksheets(1)
- If wf.CountA(.Rows("1:1")) > 1 Then Rows("1:1").Insert Shift:=xlDown
- .Range("a1").Value = wf.Text(Replace(arr(2, i), ".xls", ""), "0000年00") & "月份" & Split(Replace(arr(1, i), p, ""), "")(1) & "表"
- End With
- .Close 1
- End With
- Next
- Application.ScreenUpdating = True
- MsgBox "ok"
- Set Folder = Nothing
- Set Fso = Nothing
- End Sub
- Sub GetFiles(ByVal Folder As Object, arr$(), m&)
- Dim SubFolder As Object
- Dim File As Object
- If Folder.Path <> ThisWorkbook.Path Then
- For Each File In Folder.Files
- If File.Name Like "*.xls" Then
- m = m + 1
- ReDim Preserve arr(1 To 2, 1 To m)
- arr(1, m) = File
- arr(2, m) = File.Name
- End If
- Next
- End If
- For Each SubFolder In Folder.SubFolders
- Call GetFiles(SubFolder, arr, m)
- Next
- End Sub
复制代码 |
|