Link to home
Start Free TrialLog in
Avatar of DianaStarr
DianaStarr

asked on

vba How to highlight a default file when FilePicker Dialog opens

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.Clear
    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)
    Else
        'MsgBox "No file was selected."
        ChangeFileLocation = False
   
    End If


Avatar of Tracy
Tracy
Flag of United States of America image

Try something like this, it will sort by last modified date, to make it the first file in the dialog box:

http://www.ozgrid.com/forum/showthread.php?t=21485
Avatar of DianaStarr
DianaStarr

ASKER

Thank you for getting back so quickly, but I don't think that FileSearch will give me the functionality I'm looking for.  Tthe user must have the freedom to pick any file from the folder when the fileopen dialog pops up.  What I'm looking for is a way to highlight or select the most recent file and STILL leave the others available.  

I'm guessing that I will need to use some API calls to initialize the FileOpen dialog.

Thanks again,

d
ASKER CERTIFIED SOLUTION
Avatar of Tracy
Tracy
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
That's exactly what I needed...All I had to do was substitute my filters and provide the name of the default file.

Thank you.