- 帖子
- 258
- 主題
- 77
- 精華
- 0
- 積分
- 385
- 點名
- 0
- 作業系統
- Win7
- 軟體版本
- Office2010
- 閱讀權限
- 20
- 性別
- 男
- 來自
- Taiwan
- 註冊時間
- 2010-8-8
- 最後登錄
- 2021-1-25
|
[發問] 需要一個 選擇Excel檔案的視窗 進行選擇 然後開啟
本帖最後由 yangjie 於 2015-4-2 22:17 編輯
請教大大
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
求救
謝謝 |
|