VBA Wildcard

MarBoTJ

New Member
Joined
Mar 1, 2016
Messages
1
Hello, I've made some macros that use wildcards (Like + string) and work perfectly on a worksheet. I'd like to know if it is possible to use the same (or similar) wildcard when searching for a file to automatically open it.

Something like this

Workbooks.Open directory & Like "filename.xlsx"


Thanks in advance for your help.
 

Excel Facts

Can a formula spear through sheets?
Use =SUM(January:December!E7) to sum E7 on all of the sheets from January through December
Welcome to the Board!

Borrowing from this thread here: http://www.mrexcel.com/forum/excel-questions/559746-macro-open-all-files-folder.html, you could use code like this, with will open all files in the C:\Temp folder that start with "ABC" and have an "xlsx" extension:
Code:
Sub OpenFiles()

    Dim MyFolder As String
    Dim MyFile As String
    
    MyFolder = "C:\Temp"
    MyFile = Dir(MyFolder & "\ABC*.xlsx")
    Do While MyFile <> ""
        Workbooks.Open Filename:=MyFolder & "\" & MyFile
        MyFile = Dir
    Loop
    
End Sub
Just change the folder path and file name logic to suit your needs.
 
Last edited:
Upvote 0

Forum statistics

Threads
1,215,580
Messages
6,125,654
Members
449,245
Latest member
PatrickL

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