vba How to highlight a default file when FilePicker Dialog opens
Posted on 2009-12-21
Can anyone tell me how to highlight a default file when I show the FilePicker dialog, but still leave the other files available for selection?
There are multiple files in a folder with the same naming convention. I want to highlight the most recent file as a default, but still allow the user to select an earlier file.
Here's a code snippet
Set dlgOpen = Application.FileDialog(msoFileDialogFilePicker)
dlgOpen.Filters.Add "Excel Files (*.xls)", "*.xls", 1
FileName = "C:\temp\" & "MyFile [mmddyyyy].xls"
' -- where I would substitute the most recent date in the [mmddyyyy]
dlgOpen.InitialFileName = FileName
dlgOpen.AllowMultiSelect = False
If dlgOpen.Show = -1 Then
'set the variable that will be returned.
FilePath = dlgOpen.SelectedItems(1)
'MsgBox "No file was selected."
ChangeFileLocation = False