|
Option Explicit
Option Compare Text
Sub test()
Dim ar, i&, vFile, Filter$, strJoin$, wks As Worksheet, wks1 As Sheets
Application.DefaultFilePath = ThisWorkbook.Path & "\"
Filter = "Excel Files(*.xls*), * .xls* "
vFile = Application.GetOpenFilename(Filter, 3, "请选择文件", , False)
If vFile = False Then Exit Sub
If FileName(vFile) = ThisWorkbook.Name Then
MsgBox "不能选择与本工作簿相同文件名的工作簿!", vbCritical
Exit Sub
End If
Application.ScreenUpdating = False
Application.DisplayAlerts = False
ar = Array("1", "2", "3", "4")
strJoin = "," & Join(ar, ",") & ","
For Each wks In Worksheets
If InStr(strJoin, "," & wks.Name & ",") Then wks.Delete
Next
With GetObject(vFile)
Set wks1 = .Worksheets(ar)
wks1.Copy after:=Worksheets(Worksheets.Count)
.Close False
End With
Application.ScreenUpdating = True
Application.DisplayAlerts = True
Beep
End Sub
Function FileName(FullName As Variant) As String
Application.Volatile
FileName = Right(FullName, Len(FullName) - InStrRev(FullName, "\"))
End Function
|
|