|
原帖由 guandu 于 2011-3-17 09:32 发表
2zhaogang1960师傅您好,谢谢您的代码,但因本人水平有限,把这个代码写入我所需要的文档中就出现错误,我改了半天都不知道是哪里出错,能否再请您帮忙看下,谢谢您的帮忙
因文件过大,所以分4个文件上传,4个文件集 ...
Sub Macro1()
Dim MyPath$, MyName$, sh As Worksheet, d As Object
Dim ary(1 To 4), arr, brr(1 To 4), crr(1 To 22, 2 To 16), i&, j&, m&
Set d = CreateObject("scripting.dictionary")
MyPath = ThisWorkbook.Path & "\"
MyName = Dir(MyPath & "*.xls")
Application.ScreenUpdating = False
For Each sh In Sheets
sh.Range("B5:P26").ClearContents
m = m + 1
d(sh.Name) = m
brr(m) = crr
Next
Do While MyName <> ""
If MyName <> ThisWorkbook.Name Then
With GetObject(MyPath & MyName)
With .Sheets("保存")
.Unprotect "321"
arr = .[a1].CurrentRegion
End With
.Close False
End With
For i = 4 To UBound(arr) - 1
If d.Exists(arr(i, 1)) Then
m = d(arr(i, 1))
ary(m) = ary(m) + 1
For j = 2 To 16
brr(m)(ary(m), j) = arr(i, j)
Next
End If
Next
End If
MyName = Dir
Loop
For Each sh In Sheets
sh.[b5].Resize(ary(d(sh.Name)), 15) = brr(d(sh.Name))
Next
Application.ScreenUpdating = True
MsgBox "ok"
End Sub |
|