Forum Discussion
Can I control what is displayed in a FileDialog
Hello Excelers,
Hope you are all doing well.
Is there an option to limit the files displayed when you use something like:
With Application.FileDialog(msoFileDialogFilePciker)
.InitialFileName = "Book1"
.InitialView = msoFileDialogViewDetails
.Filters.Add "Excel Files, *.xls*"
.Title = "Choose a File"
(A way to limit files with a date range of say 7 days ago till yesterday
.Show
End With
I want to limit the files displayed by a date of 7 days ago to yesterday. I know I can use the DateLastModified of a file but the question is how to incorporate this with the msoFileDialogFilePciker.
Thanks in Advance!
GiGi
1 Reply
Unfortunately, the FileDialog object in Excel doesn’t have a built-in way to filter files by date directly — it can only filter by file type or name patterns using the .Filters property. If you want to limit the files shown to those modified within a certain date range (like from 7 days ago until yesterday), you’d need to handle that part yourself after the user selects a folder or files. A common approach is to let the user pick a folder, then use VBA code to loop through the files in that folder (using Dir or the FileSystemObject) and check each file’s DateLastModified property. You can then build a custom list or display a message box showing only the files that fit your date criteria. In short, the FileDialog can’t filter by date before showing files, but you can easily apply your own date filter afterward in code.
------------------------------------
Don't forget to mark as solution if my answer suits you