![]() |
#2
cwa99582022-03-11 08:00
|
CommonDialog能選擇資料夾嗎?
Shl.BrowseForFolder 能秀全資料夾 又 預設資料夾嗎? 查到的預設C:\ 後 D:\不會顯示
只有本站会员才能查看附件,请 登录

Private Sub Command1_Click() '選資料夾
Dim Shl As Object
Set Shl = CreateObject("Shell.Application") '創物件
Set Fd = Shl.BrowseForFolder(0, "選取資料夾", 0, "\") '標題 and 預設路徑\
If Not Fd Is Nothing Then '非錯誤執行
Text1.Text = Fd.Items.Item.Path ' 顯示所選取檔案的名稱
End If
Set Shl = Nothing '釋放
Set Fd = Nothing '釋放
End Sub
Private Sub Command2_Click() '選檔案 需物件CommonDialog1
On Error Resume Next ' 略過錯誤
CommonDialog1.Flags = cdlOFNHideReadOnly '單選 cdlOFNAllowMultiselect '改為復選
' 限制檔案類型
CommonDialog1.Filter = "All Files (*.*)|*.*|Text Files(*.txt)|*.txt|Batch Files (*.bat)|*.bat"
CommonDialog1.FilterIndex = 2 ' 預設第2 "|" 項目
CommonDialog1.ShowOpen ' 顯示「開啟舊檔」對話方塊
Text1.Text = CommonDialog1.FileName ' 顯示所選取檔案的名稱
End Sub
參考來源
選取資料夾
http://
選擇檔案
http://yes.nctu.edu.tw/vb/2_Ctrl/CommonDialog_ShowOpenSave_Demo.htm
CommonDialog.flags 參數含義
https://blog.