Skip to content

Instantly share code, notes, and snippets.

@kissmygritts
Created March 9, 2015 16:08
Show Gist options
  • Save kissmygritts/27c8063b188642cd7ace to your computer and use it in GitHub Desktop.
Save kissmygritts/27c8063b188642cd7ace to your computer and use it in GitHub Desktop.
Select a file with the Microsoft file dialog. Requires reference to Microsoft Object Library x.x, where x.x is the version number. title, start and filter correspond to Dialog Box title, the start directory and extension filters to apply.
Function PickFile(title As String, start As String, filter As String) As String
Dim dlg As FileDialog
Set dlg = Application.FileDialog(msoFileDialogFilePicker)
With dlg
.title = title
.InitialFileName = start
.AllowMultiSelect = False
.Filters.Clear
.Filters.Add filter, "*." & filter & "*", 1
If .Show = True Then
PickFile = .SelectedItems(1)
Else
Exit Function
End If
End With
End Function
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment