File Dialog Type Enumeration

Find below the list of Office file dialog types as per msoFileDialogType enumeration. The file dialog type (determined by either name or value) specifies a type of FileDialog object. The FileDialog object provides file dialog box functionality like that of standard Open and Save dialog boxes found in Microsoft Office applications.

Name

Value

Description

msoFileDialogFilePicker

3

File Picker dialog box.

msoFileDialogFolderPicker

4

Folder Picker dialog box.

msoFileDialogOpen

1

Open dialog box.

msoFileDialogSaveAs

2

Save As dialog box.

 

The code below prompts a dialog box to select a file using the FileDialog property of the Application object (which returns a FileDialog object), along with the msoFileDialogType constant to open a standard dialog box in Microsoft Office.

 Dim myDialog As FileDialog
 Set myDialog = Application.FileDialog(msoFileDialogOpen)
 myDialog.Show

 

The conditional statement below checks if the file has been open, and displays the path and name of the first selected file in a message box.

 If myDialog.Show = -1 Then
     MsgBox "The path of the selected file is " & myDialog.SelectedItems(1)
 End If

 

When selecting more than one file, we can get access to each of them looping through the selected items collection as indicated below.

 For Each fileSelected In myDialog.SelectedItems
     MsgBox "The path of the selected file is " & fileSelected
 Next fileSelected

 

Find another example using the msoFileDialogFolderPicker to list all the files in a given folder in this other post: List All Files in Folder

 

Enumerations


No comments:

Post a Comment

Popular Posts