Using Multiple Wilcards in Macro to open multiple Files

howard

Well-known Member
Joined
Jun 26, 2006
Messages
6,566
Office Version
  1. 2021
Platform
  1. Windows
I have the following code below

I need the code with the wildcard to be amended so that files containing the will display in folder to all user to select the one containing these names

Code:
 Dim FileAry As Variant, Fle As Variant
   With Application.FileDialog(3)
      .InitialFileName = "C:\My Documents\"
      .AllowMultiSelect = True
      .InitialFileName = "*Barney*","*Frame Finance*","*credit*xls*"
      If .Show Then Set FileAry = .SelectedItems()

it would be appreciated if someone could kindly assist me
 

Excel Facts

Difference between two dates
Secret function! Use =DATEDIF(A2,B2,"Y")&" years"&=DATEDIF(A2,B2,"YM")&" months"&=DATEDIF(A2,B2,"MD")&" days"
Try this:
VBA Code:
        .InitialFileName = "C:\My Documents\*Barney*.xls*;*Frame Finance*.xls*;*credit*.xls*"
 
Upvote 0
I have several csv files in folder C:\downloads that I need to open that contains "BTMK" for eg Increases BTMK June 2020.csv, increases BTMK July 2020.csv etc

I have used a wildcard to open only the files that contain BTMK in folder C:\downloads but all csv files in this folder are being displayed


Kindly check my code and amend

your assistance is most appreciated

Code:
 Sub Open_Workbook()
A:
Dim A As Variant
Dim LR As Long
A = Application.GetOpenFilename(MultiSelect:=True)
If TypeName(A) = "Boolean" Then Exit Sub

Dim file As Variant

Dim FileAry As Variant, Fle As Variant
With Application.FileDialog(3)
.AllowMultiSelect = True
.InitialFileName = "C:\downloads\*Increases*BTMK*.csv*"
If .Show Then Set FileAry = .SelectedItems()
End With
For Each file In FileAry
   If TypeName(A) = "Boolean" Then Exit Sub



Application.ScreenUpdating = False
           With Workbooks.Open(file)

    
With Sheets(1)
.Range("a1", .Range("O" & Rows.Count).End(xlUp)).Copy _
Destination:=ThisWorkbook.Sheets(1).Range("A" & Rows.Count).End(xlUp).Offset(1)


End With

.Close SaveChanges:=False
End With
Next
Application.ScreenUpdating = True
End Sub
 
Upvote 0
You should have started a new thread since this issue is unrelated to specifying multiple wildcards in the InitialFileName property.

It looks like you're mixing GetOpenFileName and Application.FileDialog, so I would delete everything relating to the former.
 
Upvote 0

Forum statistics

Threads
1,215,471
Messages
6,124,996
Members
449,201
Latest member
Lunzwe73

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