Vba file dialog in Excel

Folder picker is one of the four objects of a dialog box control in Excel vba.

To use a folder picker, the "msoFileDialogFolderPicker" has to be referenced.

This dialog box is very useful, when there is a need to select a folder in the application.

For example, consider a situation, when a set of excel files has to be manipulated programatically.

In such a case, the user will be opted to choose the folder containing the excel files, here is where the folder dialog comes to the rescue.

The following example illustrates the folderpicker.

  1. Sub folderpkr()
  2. Dim fldr As FileDialog
  3. Dim sItem As String
  4. Set fldr = Application.FileDialog(msoFileDialogFolderPicker)
  5. With fldr
  6. .Title = "Select a Folder"
  7. .AllowMultiSelect = False
  8. .InitialFileName = Application.DefaultFilePath
  9. If .Show <> -1 Then GoTo NextCode
  10. sItem = .SelectedItems(1)
  11. End With
  12. MsgBox "You have selected " & sItem & " folder"
  13. NextCode:
  14. GetFolder = sItem
  15. Set fldr = Nothing
  16. End Sub

The above example is a simple illustration of this dialog box that displays the selected folder to the user.

The Screenshot of the code and its outputs are as shown below:

excel vba file dialog

excel vba file dialog

excel vba file dialog


You can find similar Excel Questions and Answer hereunder

1) After several iterations, I have finalized my WorkBook - how do I make it Read-only from then on to prevent further edits?

2) Write to text file without quotes in vba in Excel

3) Here an explanation about how to control the folder dialog that will let you access to your files using VBA

4) How to copy files in Excel VBA is explained here

5) How can I check if a file exists in a folder using VBA?

6) How can I extract file name from a full path including folder path and file name?

7) How can I change the meta-data of file (Author, Company Name and the like)?

8) Import txt file in Excel

9) I have WorkBook with sensitive confidential information - how do I encrypt / protect my file so that access to file contents is restricted?

10) How can I get users to select a file for processing using my macro?


Here the previous and next chapter