Vba display open dialog box explorer in Excel

For example, my macro takes a file that is selected by user as input, processes the same and provides output file. In Excel, how can I get user to select a file?

To do it in Excel, here is the answer:

  1. Option Explicit
  2. Sub ChooseFile()
  3. Dim blnResponse As Boolean
  4. ' Show the Open dialog box.
  5. blnResponse = Application.Dialogs(xlDialogOpen).Show("*.xls")
  6. ''
  7. ' If blnResponse is False (Open dialog canceled), exit the procedure.
  8. If blnResponse = False Then
  9. Exit Sub
  10. End If
  11. ''
  12. 'File Processing and Output generation code goes here.
  13. ''
  14. End Sub


a) Line 5 brings up a dialog box as shown below. User can then select a file and click "Open". Instead of displaying all files use of ("*.xls") filter ensures only Excel files are shown.

excel vba display open dialog box explorer


You can find similar Excel Questions and Answer hereunder

1) How can I dynamically add a hyperlink using VBA?

2) Here an explanation about the file dialog and how to control in with VBA

3) Here an explanation about list box and how to control list boxes in Excel VBA

4) Here an explanation about text box and how to control text boxes in Excel VBA

5) Here an explanation about frames and how to control frames in Excel VBA

6) How can worksheet functions be accessed in VBA?

7) How can I add a legend to a chart using VBA?

8) How can I copy and rename a WorkSheet using VBA?

9) How can I remove display of Gridlines in my worksheet using VBA?

10) Line break in vba message box in Excel


Here the previous and next chapter