vba display open dialog box explorer in Excel

Q149. In Excel, how can I get users to select a file for processing using my macro?

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

Description:

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 set Page orientation, Zoom % , Title Rows and footer using VBA?

2) How can I get row count of filtered data?

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

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

5) Import txt file in Excel

6) How can I delete all shapes in a WorkSheet?

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

8) How can I find the number of working days between 2 dates using VBA?

9) How can I set the fill color, font color and set number format of cell to date?

10) How do I restrict user entry in ActiveX Text Box to just numeric values?

11) Vba length of an array in Excel

12) How can I display list of NAMES in a worksheet?

13) How do I add a shape using VBA?

14) How can I set the Source Data of charts using VBA?

15) How can I add a WorkSheet and name it as required using VBA?