|
Option Explicit
Sub test()
Dim br, i&, strFileName$, strPath$, strJoin$
Application.ScreenUpdating = False
Application.DisplayAlerts = False
strPath = ThisWorkbook.Path & "\"
br = [{"A.xlsx","";"B.xlsx",""}]
strJoin = "," & "A.xlsx" & "," & "B.xlsx" & ","
For i = 1 To UBound(br)
strFileName = Dir(strPath & br(i, 1))
If strFileName = "" Then
MsgBox br(i, 1) & "文件不存在,请检查!": Exit Sub
End If
Next i
For i = 1 To UBound(br)
With GetObject(strPath & br(i, 1))
Set br(i, 2) = .Worksheets(1)
End With
Next i
strFileName = Dir(strPath & "*.xls*")
Do Until strFileName = ""
If strFileName <> ThisWorkbook.Name Then
If InStr(strJoin, "," & strFileName & ",") = False Then
With Workbooks.Open(strPath & strFileName, 0)
If .Worksheets(1).Name <> "说明" Then br(1, 2).Copy before:=.Worksheets(1)
If .Worksheets(.Worksheets.Count).Name <> "内容" Then _
br(2, 2).Copy after:=.Worksheets(.Worksheets.Count)
.Close True
End With
End If
End If
strFileName = Dir
Loop
For i = 1 To UBound(br)
Set br(i, 2) = Nothing
Workbooks(br(i, 1)).Close False
Next i
Application.ScreenUpdating = True
Application.DisplayAlerts = True
Beep
End Sub
|
|