Getting VBA to recognise a file using only part of the file name as the rest is variable?

booms

Board Regular
Joined
Dec 2, 2010
Messages
60
Hi,

I’m trying to set up a VBA macro to copy a list of files to another directory.

Up until now I’ve been using FileCopy and building up the directory path of the source file and telling it what output directory to use – nice and straightforward

There’s now been a change to the naming convention of the files however that has broken this.

Whereas the source files used to be called something like

Accounting_File_1_12032018.txt

(and it was easy to get the macro to recognise this with a bit of code to deal with the changing date)

However, now all the source files are preceded by a long string of alphanumeric random characters which may change – but the length of which is always the same e.g.

Asd8fa9f78sd7f9a87df9s7f_ Accounting_File_1_12032018.txt
8asdf84978sdf7a98sdf7s9e_Accounting_File_1_13032018.txt

Is there any way I can get my macro to identify the correct files only by using the right-hand side of the name of the file (which can be predicted)

Thanks
 
Ah, wow. I can just use an asterisk on each side of e.g. Accounting_File.csv and it'll pick it up?

I'll give that a go.
 
Upvote 0

Excel Facts

Do you hate GETPIVOTDATA?
Prevent GETPIVOTDATA. Select inside a PivotTable. In the Analyze tab of the ribbon, open the dropown next to Options and turn it off
I can just use an asterisk on each side of e.g. Accounting_File.csv and it'll pick it up?
Yep. Wildcards don't just have to be at the end, or the beginning, they can be both!
 
Upvote 0

Forum statistics

Threads
1,223,909
Messages
6,175,312
Members
452,634
Latest member
cpostell

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