Application.GetOpenFilename suggest default file

savindrasingh

Board Regular
Joined
Sep 10, 2009
Messages
183
Hello Experts,

I have below code in one of my macro projects:

Code:
RunBookCrtF = Application.GetOpenFilename("Runbook file in YYYY-MM-DD format (*.xlsx),*.xlsx", 1, "Select latest date Runbook Critical Fields Report file")

This will prompt the user to open one workbook which is required for executing a macro. When this file open dialog box appears on screen it is displaying 4-5 different filenames in default folder under which this dialogbox is displayed.

My requirement is it should display only filename starting with 20*.xlsx because the file I want the user should open is in YYYY-MM-DD.xlsx format and it can be any date from this week ex. 2010-04-27.xlsx.

This way I can prevent user from selecting a wrong file to be opened.

Is that possible to apply this kind of filter?
 

Excel Facts

Highlight Duplicates
Home, Conditional Formatting, Highlight Cells, Duplicate records, OK to add pink formatting to any duplicates in selected range.
This is what I have used as a solution:

Code:
Dim FileToDiag  As FileDialog
Set FileToDiag = Application.FileDialog(msoFileDialogFilePicker)
repPath="C:\Temp"
With FileToDiag
    .AllowMultiSelect = False
    .InitialFileName = repPath & Application.PathSeparator & "20*.xlsx"
    .ButtonName = "Open Selection"
    .Title = "Select Runbook file to open"
    .Filters.Add "Runbook file in YYYY-MM-DD.xlsx format", "*.xlsx; *.xls", 1
    .Show
 
    For Each fileSelected In .SelectedItems
        RunBookCrtF = fileSelected
    Next
End With

Thanks to Andrew :)
 
Last edited:
Upvote 0

Forum statistics

Threads
1,215,013
Messages
6,122,694
Members
449,092
Latest member
snoom82

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top