Skip to content

Instantly share code, notes, and snippets.

@chilismaug
Created April 10, 2019 13:40
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save chilismaug/edb433d994b4b808c1efbb11c84cc83e to your computer and use it in GitHub Desktop.
Save chilismaug/edb433d994b4b808c1efbb11c84cc83e to your computer and use it in GitHub Desktop.
vba pick a file to open
Private Sub openDialog()
Dim fd As Office.FileDialog
Set fd = Application.FileDialog(msoFileDialogFilePicker)
With fd
.AllowMultiSelect = False
' Set the title of the dialog box.
.Title = "Please select the file."
' Clear out the current filters, and add our own.
.Filters.Clear
.Filters.Add "Excel 2003", "*.xls"
.Filters.Add "All Files", "*.*"
' Show the dialog box. If the .Show method returns True, the
' user picked at least one file. If the .Show method returns
' False, the user clicked Cancel.
If .Show = True Then
txtFileName = .SelectedItems(1) 'replace txtFileName with your textbox
End If
End With
End Sub
@chilismaug
Copy link
Author

thanks to eabraham stack-O answer

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment