workbooks.open with file browser

lezawang

Well-known Member
Joined
Mar 27, 2016
Messages
1,805
Office Version
  1. 2016
Platform
  1. Windows
Hi

I want to improve the code below. I am thinking if it is possible to display file browser for the user to choose file from. Like when you click open in Excel, a file browser will be opened to help users to select a file. Can I do that here? Thank you very much

Code:
Sub wbs_open()
    Dim xfile As String
    xfile = InputBox("enter file name with full path")
    Workbooks.Open Filename:=xfile
End Sub
 

Excel Facts

Create a Pivot Table on a Map
If your data has zip codes, postal codes, or city names, select the data and use Insert, 3D Map. (Found to right of chart icons).
or ...
Code:
Sub FilePickerMethod()
    Dim xfile As String
    With Application.FileDialog(msoFileDialogFilePicker)
            .InitialFileName = "C:\Folder\SubFolder\"       'Set the initial path like this (optional)
            .AllowMultiSelect = False
            .Filters.Add "Excel Files", "*.xls; *.xlsx; *.xlsm; *.xlsb", 1      'add filters to narrow down file choices (optional)
            .Show
            If .SelectedItems.Count > 0 Then
                xfile = .SelectedItems.Item(1)
            Else
                Exit Sub
            End If
    End With
    Workbooks.Open xfile
End Sub


https://analystcave.com/vba-application-filedialog-select-file/
 
Last edited:
Upvote 0

Forum statistics

Threads
1,213,496
Messages
6,113,995
Members
448,539
Latest member
alex78

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top