|
- Public Arr1(), r%, strTmp$, nm$
- Function GetFileFolderList(ObjFolder) As String
- Dim SubFolders, SubFolder, hz$
- Dim Files, File
- hz = "xls" '指定后缀
- Set Files = ObjFolder.Files
- If Files.Count <> 0 Then
- For Each File In Files
- If Right(File, 3) = hz Then
- r = r + 1
- ReDim Preserve Arr1(1 To r)
- Arr1(r) = File
- End If
- Next
- End If
- Set SubFolders = ObjFolder.SubFolders
- If SubFolders.Count <> 0 Then
- For Each SubFolder In SubFolders
- strTmp = GetFileFolderList(SubFolder)
- Next
- End If
- GetFileFolderList = strTmp
- End Function
- Sub yy()
- Dim fso, folder, myPath$, Filename$, wb1 As Workbook, m&, Arr
- Dim Sht1 As Worksheet, i&, nm1$, wbnm$, sh As Worksheet, Myr&, Myc&
- Application.ScreenUpdating = False
- r = 0
- myPath = ThisWorkbook.Path & ""
- Set wb1 = ThisWorkbook
- wbnm = Left(wb1.Name, Len(wb1.Name) - 4)
- Set fso = CreateObject("Scripting.FileSystemObject")
- Set folder = fso.GetFolder(myPath)
- strTmp = GetFileFolderList(folder)
- For i = 1 To r
- Filename = Arr1(i)
- nm1 = Split(Mid(Filename, InStrRev(Filename, "") + 1), ".")(0)
- If nm1 = wbnm Then GoTo 200
- Workbooks.Open Filename
- Dim wb As Workbook
- Set wb = ActiveWorkbook
- For Each sh In wb.Sheets
- Myr = sh.[b65536].End(xlUp).Row
- Myc = sh.[iv2].End(xlToLeft).Column
- nm = sh.Name
- If Myr > 2 Then
- Arr = Range("a3", Cells(Myr, Myc))
- With wb1.Sheets(nm)
- m = .[b65536].End(xlUp).Row + 1
- .Cells(m, 1).Resize(UBound(Arr), UBound(Arr, 2)) = Arr
- End With
- End If
- Next
- wb.Close savechanges:=False
- Set wb = Nothing
- 200:
- Next
- Application.ScreenUpdating = True
- End Sub
复制代码 |
|