vba How to highlight a default file when FilePicker Dialog opens

Posted on 2009-12-21
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
    LVL 24

    Expert Comment

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

    Author Comment

    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

    Have a look at this, it's the API call to the Open Dialog box:

    Author Closing Comment

    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.

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Do You Know the 4 Main Threat Actor Types?

    Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

    MS Access 2003 or later To MySQL Migration Project Hello All, this is my second article in the category of MS-OFFICE Automation. In internet I am not able to find any comprehensive resource on the Migration of MS Access back-end to MySQL so I fin…
    The new Microsoft OS looks great, is easier than ever to upgrade to, it is even free.  So what's the catch?  If you don't change the privacy settings, Microsoft will, in accordance with the (EULA) you clicked okay to without reading, collect all the…
    The viewer will learn how to create two correlated normally distributed random variables in Excel, use a normal distribution to simulate the return on different levels of investment in each of the two funds over a period of ten years, and, create a …
    This Micro Tutorial will demonstrate how to create pivot charts out of a data set. I also added a drop-down menu which allows to choose from different categories in the data set and the chart will automatically update.

    779 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

    Need Help in Real-Time?

    Connect with top rated Experts

    13 Experts available now in Live!

    Get 1:1 Help Now