我依大大指導 作如此 step by step寫法 但速度不快
應如何修訂
Sub copysheet1()
Dim wb1 As Workbook, wb2 As Workbook
Dim wb As Workbook
Dim Path1, str1, str2 As String
Path1 = Application.ActiveWorkbook.Path
Set wb = ActiveWorkbook
wb.Activate
Application.EnableEvents = False
Application.ScreenUpdating = False
Application.DisplayAlerts = False
ChDrive Split(Path1, ":")(0)
ChDir Path1
Dim Filt As String
Dim FilterIndex As Integer
Dim FileName As Variant
Dim xlfileName As String
Dim Title As String
Filt = "Excel Files (*.xls),*.xls"
FilterIndex = 5
Title = "選擇資料匯入之來源Excel檔"
FileName = Application.GetOpenFilename _
(FileFilter:=Filt, _
FilterIndex:=FilterIndex, _
Title:=Title)
If UCase(FileName) = "FALSE" Then
MsgBox "No file was selected."
Exit Sub
End If
xlfileName = Dir(FileName)
If IsOpen(xlfileName) Then
Workbooks(xlfileName).Activate
Set wb1 = Workbooks(xlfileName)
Else
Set wb1 = Workbooks.Open(FileName, True, False)
End If
wb1.Activate
For i = 1 To wb1.Sheets.Count
If wb1.Sheets(i).Name <> "國中" Then
For j = 1 To wb.Sheets.Count
If wb.Sheets(j).Name = wb1.Sheets(i).Name Then
wb.Sheets(j).Copy After:=wb.Sheets(wb.Sheets.Count)
wb.Sheets(j).Delete
Exit For
End If
Next
wb1.Sheets(i).Copy After:=wb.Sheets(wb.Sheets.Count)
End If
Next
wb1.Close SaveChanges:=False
' wb2.Close True
Application.DisplayAlerts = True
Application.ScreenUpdating = True
Application.EnableEvents = True
End Sub作者: stillfish00 時間: 2013-9-26 14:52