How to use filter in filedialog ?

rodrigo_m_almeida

New Member
Joined
Jan 13, 2022
Messages
42
Office Version
  1. 2021
Platform
  1. Windows
Good Morning,

Needed to filter the selection of files by the initials of the filename and extension

Example :

Display files with ABC initials and CSV extension

ABC123.CSV
ABC321.CSV
ABCSCHOOL.CSV
ABCMEDIC.CSV

Etc...

VBA Code:
' Declare Variables
        Dim xPathName As Variant, xFileName As String
' Browse File
        With Application.FileDialog(msoFileDialogFilePicker)
            .AllowMultiSelect = False
            .Title = "Select File:"
            With .Filters
                .Clear
                .Add "Excel Files", "*.csv*"     ' Search Filter <
            End With
            If .Show() Then xFileName = .SelectedItems(1) Else Exit Sub
        End With
' Open File
        Workbooks.Open Filename:=xFileName, Delimiter:=";", Local:=True

Anyone have an idea how to do this ?
 

Excel Facts

How to calculate loan payments in Excel?
Use the PMT function: =PMT(5%/12,60,-25000) is for a $25,000 loan, 5% annual interest, 60 month loan.
Did you research the use of the dialog in your other thread on this as I suggested

because you probably would have learned more by researching as opposed to being handed code like that.
Using the InitialFileName property with wild card is an option, in conjunction with the .Filter property.
 
Upvote 0
BTW, you should not need the .Filter property because you can specify the file extension in the InitialFileName property (which will limit your extension choices to one file type). Could use
.InitialFileName = "C:\. . .\ABC*.CSV"
 
Upvote 0
Solution
BTW, you should not need the .Filter property because you can specify the file extension in the InitialFileName property (which will limit your extension choices to one file type). Could use
.InitialFileName = "C:\. . .\ABC*.CSV"
You are inspiration...
Thanks for all !
 
Upvote 0

Forum statistics

Threads
1,214,925
Messages
6,122,303
Members
449,078
Latest member
nonnakkong

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