Created
December 22, 2021 19:25
-
-
Save Se7enSquared/716150a777fc4b1711798e61389ede68 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
' ---------------------------------------------------------------- | |
' Function: ChooseExcelFile | |
' Purpose: Get the location of the chosen excel file from dialog | |
' Params: String: starting_path: The folder to open the dialog in | |
' example: Environ$("USERPROFILE") & "\Downloads" or | |
' example2: C:\Data (no ending \) | |
' Returns: String: The full path to the chosen excel file as string | |
' By: HG | |
' Date: 12/21/2021 | |
' ---------------------------------------------------------------- | |
Private Function OpenExcelFile(starting_path As String) As String | |
Dim fd As Office.FileDialog | |
Dim fileName As String | |
Set fd = Application.FileDialog(msoFileDialogFilePicker) | |
On Error GoTo nofilechosen | |
With fd | |
.Filters.Clear | |
.Filters.Add "Excel Files", "*.xlsx?", 1 | |
.Title = "Choose an Excel file" | |
.AllowMultiSelect = False | |
.InitialFileName = starting_path | |
If .Show = True Then | |
fileName = fd.SelectedItems(1) | |
OpenExcelFile = fileName | |
End If | |
End With | |
Exit Function | |
nofilechosen: | |
MsgBox "No file was selected. Please try again." | |
End | |
End Function |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment