Wild Card in VBA

aclare

Board Regular
Joined
Nov 30, 2007
Messages
110
I have a weird situation. I use a macro to grab a set of 4 reports and attach them to an e-mail tied to a specific e-mail address. The system that generates the report started saving a random number to the end of the file, so they are:

Fund Report_12345.xls
Fund Report_02958.xls

Is there a way in either excel or VBA to have a wild card (i.e. Fund Report_*.xls) so that the file will get picked up even if I don't know the random number?
 

Excel Facts

Difference between two dates
Secret function! Use =DATEDIF(A2,B2,"Y")&" years"&=DATEDIF(A2,B2,"YM")&" months"&=DATEDIF(A2,B2,"MD")&" days"
Short answer is Yes

You sort of answered it yourself : Fund Report_*.xls

But with out knowing how you attached the files before difficult to help any further
 
Upvote 0
Short answer is Yes

You sort of answered it yourself : Fund Report_*.xls

But with out knowing how you attached the files before difficult to help any further

Do I put the wild card in VBA? I tried:

Code:
 oldname = Range("A" & i).Value & "*" & Range("B" & i).Value

in cell A1, I have: Fund Report
in cell B1, I have: .xls

It doesn't seem to be working as it thinks the file name is now FundReport*.xls.
 
Upvote 0
Nevermind... I figured it out... for everyone's benefit, this is what I used:

Code:
 oldname = Dir("C:\" & Range("A" & i).Value & "_*" & Range("B" & i).Value)

This finds a file name in the C:\ directory with a wild card
 
Upvote 0

Forum statistics

Threads
1,222,405
Messages
6,165,864
Members
451,988
Latest member
boo203

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