フォルダ選択ダイアログボックスの表示

Sub Sample()
    Dim res As Boolean
    res = SelectFolder
    'フォルダ名取得成功時の処理
End Sub
'*******************************************************
'フォルダ選択ダイアログボックスの表示 戻り値:成功か否か
'*******************************************************
Function SelectFolder() As Boolean

    With Application.FileDialog(msoFileDialogFolderPicker)
        .Title = "フォルダ選択"
        If .Show = True Then
            'フォルダ名取得後の処理
            MsgBox .SelectedItems(1) 'フルパス
            SelectFolder = True
        Else
            '処理
            SelectFolder = False
        End If
    End With
End Function

コメント