|
Sub 合并()
Application.ScreenUpdating = False
Dim d As Object
Dim rr()
ReDim rr(1 To 5000)
Set d = CreateObject("scripting.dictionary")
lj = ThisWorkbook.Path & "\合并学校工作簿\"
f = Dir(lj & "*.xls*")
Do While f <> ""
n = n + 1
rr(n) = lj & f
zd = Left(f, 4)
d(zd) = ""
f = Dir
Loop
For Each k In d.keys
m = 0
For i = 1 To n
If InStr(rr(i), k) > 0 Then
m = m + 1
Set wb = Workbooks.Open(rr(i))
mc = Replace(Split(wb.Name, ".")(0), k, "")
If m = 1 Then
wb.Worksheets(1).Copy
Set ww = ActiveWorkbook
ww.Worksheets(1).Name = mc
Else
wb.Worksheets(1).Copy after:=ww.Worksheets(ww.Worksheets.Count)
ww.Worksheets(ww.Worksheets.Count).Name = mc
End If
wb.Close False
End If
Next i
ww.SaveAs Filename:=ThisWorkbook.Path & "\" & k & ".xlsx"
ww.Close
Next k
Application.ScreenUpdating = True
MsgBox "ok!"
End Sub
|
|