請教大大
Sub openfile()
Dim FileName As String
Dim xlfileName As String
Dim wb As ActiveWorkbook
Set wb = ActiveWorkbook
wb.Activate
path1 = ActiveWorkbook.Path
ChDir path1
需要一個 選擇檔案的視窗 進行選擇 不會寫
Title = "Select a File to Import"
選擇FileName(2003 或 2010均可以被選) If FileName = False Then
MsgBox "No file was selected."
Exit Sub
End If
xlfileName = Dir(FileName)
Application.EnableEvents = False
If IsOpen(xlfileName) Then
Workbooks(xlfileName).Activate
Set wb1 = Workbooks(xlfileName)
Else
Set wb1 = Workbooks.Open(FileName)
End If
wb1.Activate
End If
Application.EnableEvents = True
On Error Resume Next
wb1.Activate
end Sub
Function IsOpen(fs As String) As Boolean
IsOpen = False
For Each w In Windows
If w.Caption = fs Then IsOpen = True: Exit For
Next
End Function