|
替换这段代码看看。- 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
- a = InStr(wb1.Name, ".")
- If a = 4 Then
- wbnm = Left(wb1.Name, Len(wb1.Name) - 4)
- ElseIf a = 5 Then
- wbnm = Left(wb1.Name, Len(wb1.Name) - 5)
- End If
- 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
复制代码 |
|