none
How to use vba to show up a directory box RRS feed

  • Question


  • How do you guys call this ? It shows up when I am going to save the file? I can select which directory I want to save the file?

    BUt the most important question is: how to show this up using VBA?

    Tuesday, April 7, 2015 8:24 AM

Answers

  • If you want to display the Save As dialog (and save the document if the user clicks Save):

        Application.Dialogs(wdDialogFileSaveAs).Show

    If you want to display the Save As dialog and retain the path and filename specified by the user:

        Dim strFile As String
        With Application.FileDialog(2) ' msoFileDialogSaveAs
            If .Show Then
                strFile = .SelectedItems(1)
            End If
        End With

    strFile will contain the path and filename specified by the user, or be an empty string if the user cancels the dialog.

    If you want to display a dialog in which the user can select a folder:

        Dim strFolder As String
        With Application.FileDialog(4) ' msoFileDialogFolderPicker
            If .Show Then
                strFolder = .SelectedItems(1)
            End If
        End With

    strFolder will contain the path of the folder selected by the user, or be an empty string if the user cancels the dialog.

    Regards, Hans Vogelaar (http://www.eileenslounge.com)

    Tuesday, April 7, 2015 1:49 PM