Learn how to a build a cloud-first strategyRegister Now


vba How to highlight a default file when FilePicker Dialog opens

Posted on 2009-12-21
Medium Priority
Last Modified: 2012-05-08
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
    End If

Question by:DianaStarr
  • 2
  • 2
LVL 24

Expert Comment

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


Author Comment

ID: 26100033
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,

LVL 24

Accepted Solution

Tracy earned 2000 total points
ID: 26100107
Have a look at this, it's the API call to the Open Dialog box:


Author Closing Comment

ID: 31668685
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.

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Freeze panes is an option within all variants of Excel to enable parts of a sheet to remain stationary when the cursor is in another part of the sheet. This is a very useful feature which is overlooked or under used.
Microsoft's Excel has many features that most people will never need nor take advantage of.  Conditional formatting is one feature that you may find a necessity once you start using it.
This Micro Tutorial will demonstrate in Google Sheets how to use the HYPERLINK function to create live links inside your spreadsheet.
This Micro Tutorial will demonstrate how to use a scrolling table in Microsoft Excel using the INDEX function.

810 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question