請教各位先進們
在表單裡 想用視窗作選擇 得到 某一個資料匣名字(含路徑) 應如下語法?
類似如下視窗作選擇 得到 某一個檔
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)
而我需要的是 選擇資料夾 進而取得其資料夾名字。
求救於先進們 謝謝作者: yangjie 時間: 2014-3-22 01:02
回復 1#yangjie
自行參考說明 自編成如下:
Sub getfolder()
Dim f1 As Object
Set f1 = CreateObject("Scripting.FileSystemObject")
Dim fd As FileDialog
Set fd = Application.FileDialog(msoFileDialogFilePicker)
Dim vrtSelectedItem As Variant
With fd
.Filters.Add "Images", "*.gif; *.jpg; *.jpeg", 1
.FilterIndex = 2
If .Show = -1 Then
For Each FileName In .SelectedItems
FolderName = f1.GetParentFolderName(Path:=FileName)
Next FileName
End If
End With
Set f1 = Nothing
Set fd = Nothing
End Sub
但不會設定成只能選一個? 請教教我!作者: GBKEE 時間: 2014-4-2 10:22