Windows
2.フォルダ選択ダイアログを使用する
1.単純な例
注意:あらかじめ Microsoft Shell Controls And Automation に参照設定をしておくこと。
参照設定([プロジェクト]メニューの[参照設定])の一覧にこれがない場合にはこの方法ではフォルダ選択ダイアログは使用できない。
Dim oShell As New Shell
Dim oFolder As Folder2
Set oFolder = oShell.BrowseForFolder(0, "選択してください。", 1)
If Not (oFolder Is Nothing) Then
MsgBox oFolder.Items.Item.Path & "\" & oFolder.Title
Else
MsgBox "キャンセルされました。"
End If
メモ:この例を実行するにはversion 4.71以上のShell32.dllが必要。Shell32.dllはWindows\Systemフォルダ(またはwinnt\system32フォルダ)内に必ずあるのでプロパティでバージョンを確認できる。
2.参照設定をしない例
Dim oShell As Object
Dim oFolder As Object
Set oShell = CreateObject("Shell.Application")
Set oFolder = oShell.BrowseForFolder(0, "選択してください。", 1)
If Not (oFolder Is Nothing) Then
MsgBox oFolder.Items.Item.Path & "\" & oFolder.Title
Else
MsgBox "キャンセルされました。"
End Ifメモ:この例を実行するのに必要な環境は不明。上の例1よりも古い環境でも実行できるはず。