FileDialog to only show xlsx files containing certain text

j4ttlife

New Member
Joined
Feb 2, 2022
Messages
30
Platform
  1. Windows
  2. MacOS
Hi, in my Macro I have added a FileDialog popup for users to select a file.

However, sometimes the subfolders contain a lot of files. I would like to narrow down the number of files visible to reduce the likelihood of a user selecting the wrong file.

Is it possible for me to add a line to the FileDialog to only show files containing certain text?

For example, suppose my files were named by a specific month and I only wanted to see files containing *Sep* to show only the September files, is this something you are able to do within VBA?



Currently I have added a Title and Initial file name to help the user, but this is still open to error.

VBA Code:
Dim fd As FileDialog
Dim SepData As Workbook
Dim lastRow As Long
 
Set fd = Application.FileDialog(msoFileDialogOpen)
 
With fd
 
    .Filters.Clear
    .Title = "Select Sep Data"
    .AllowMultiSelect = False
    .InitialFileName = "Sep Data"

     If .Show Then Set SepData = Workbooks.Open(.SelectedItems(1))
     .Execute

End With
 

Excel Facts

What do {} around a formula in the formula bar mean?
{Formula} means the formula was entered using Ctrl+Shift+Enter signifying an old-style array formula.
Change the initial file name to "*sep*"
 
Upvote 0
Solution
You're welcome & thanks for the feedback.
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,176
Members
453,021
Latest member
Justyna P

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