- 帖子
- 258
- 主題
- 77
- 精華
- 0
- 積分
- 385
- 點名
- 0
- 作業系統
- Win7
- 軟體版本
- Office2010
- 閱讀權限
- 20
- 性別
- 男
- 來自
- Taiwan
- 註冊時間
- 2010-8-8
- 最後登錄
- 2021-1-25
|
回復 4# Hsieh
謝謝Hsieh版主協助function Isopen()的指導
自個兒稍微有點突破
Sub 選擇檔名匯入()
Dim Path1, Str1 As String
Dim wb As Workbook
Path1 = Application.ActiveWorkbook.Path
Dim Filt As String
Dim FilterIndex As Integer
Dim fileName As Variant
Dim Title As String
Filt = "Excel Files (*.xls),*.xls"
FilterIndex = 5
Title = "Select a File for Import"
fileName = Application.GetOpenFilename _
(FileFilter:=Filt, _
FilterIndex:=FilterIndex, _
Title:=Title)
If fileName = False Then
MsgBox "No file was selected."
Exit Sub
End If
Dim fso3
Set fso3 = CreateObject("Scripting.FileSystemObject")
GetAn3 = fso3.GetbaseName(fileName)
If IsOpen(GetAn3 & ".xls") <> False Then
Workbooks(GetAn3 & ".xls").Activate
Else
Set wb = Workbooks.Open(fileName, True, False)
End If
f_bookname2 = ActiveWorkbook.Name
Windows(f_bookname2).Activate
Sheets(1).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
再請教大大
1. 如何讓Application.GetOpenFilename 所開之視窗為path1?
2.可有更好的寫法?
謝謝 |
|