Do wildcards work when trying to open a file using VBA?

Gundisalvus

New Member
Joined
Jan 27, 2023
Messages
4
Office Version
  1. 365
Platform
  1. Windows
Hello, I have a macro that should run monthly on a file that has a specific title only changing dependind on the month, example: "M02 - Royalty" can I make it open using wildcards?
something like "M## - Royalty"?
sorry for such a basic question but its sensible data and I am scared I might do something to it unintentionally.
 

Excel Facts

VLOOKUP to Left?
Use =VLOOKUP(A2,CHOOSE({1,2},$Z$1:$Z$99,$Y$1:$Y$99),2,False) to lookup Y values to left of Z values.
Wildcards requires using the dir command.

VBA Code:
Dim wordapp: Set wordapp = CreateObject("word.Application")
    wordapp.Documents.Open ("C:\Monthly_Reports\Customer_02\" & Dir("C:\Monthly_Reports\Customer_02\My Customer Report*.docx"))
    wordapp.Visible = True
 
Upvote 0
The example was how to use the dir -command, but here is another version that is for excel.

VBA Code:
Workbooks.Open Filename:=("P:\Excel\" & Dir("P:\Excel\M* - Royalty.xlsm"))
 
Upvote 0

Forum statistics

Threads
1,215,429
Messages
6,124,839
Members
449,193
Latest member
MikeVol

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