Name

Application.FileDialog (MsoFileDialogType)

Synopsis

Returns the FileDialog object.

Argument

Description

Settings

MsoFileDialogType

Determines which Excel dialog to return

msoFileDialogFilePicker

msoFileDialogFolderPicker

msoFileDialogOpen

msoFileDialogSaveAs

The following code displays the file picker dialog box and lets the user select a text file to open in Notepad:

Sub TestFileDialog(  )
    Dim fname As String
    With Application.FileDialog(msoFileDialogFilePicker)
        .AllowMultiSelect = False
        .Filters.Add "Text files (*.txt)", "*.txt", 1
        .FilterIndex = 1
        .Title = "Open text file"
        If .Show = True Then _
          Shell "notepad.exe " & .SelectedItems(1)
    End With
End Sub

Get Programming Excel with VBA and .NET now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.