vba wildcard - FileCopy

p4nny

Board Regular
Joined
Jan 13, 2015
Messages
246
Hi

I'm using the FileCopy function to copy files from one location to another.

I would like to change slightly so that I can use a wildcard

For example:

\\homedrivestmp\homedisk1\saery\Desktop\test250118.xlsx

Rather than specify the file name as above, I would like to target files where the file name is 'like' "test"&??0118

is this possible?

Many thanks
 

Excel Facts

Can you AutoAverage in Excel?
There is a drop-down next to the AutoSum symbol. Open the drop-down to choose AVERAGE, COUNT, MAX, or MIN
Try using the FileSystemObject instead. Here's an example...

Code:
Sub test()

    Dim fso As Object
    
    Set fso = CreateObject("Scripting.FileSystemObject")


    fso.CopyFile "c:\users\domenic\documents\test??0118.xlsx", "c:\users\domenic\desktop"
 
    Set fso = Nothing


End Sub

Hope this helps!
 
Upvote 0
Works great thank you,

How would I wildcard the word "test" as it could be test, test1, test2, test3, test10, test100 etc
 
Upvote 0
That's great, glad I could help. For your subsequent question, try...

Code:
fso.CopyFile "c:\users\domenic\documents\test*.xlsx", "c:\users\domenic\desktop"

If you want to add it to your previous criteria, try...

Code:
fso.CopyFile "c:\users\domenic\documents\test*??0118.xlsx", "c:\users\domenic\desktop"

Hope this helps!
 
Upvote 0
Hi

I have a filename as follows: "IT COS 120118"

How would I find amend so to find files with the filename like "IT" *ignoring the rest of the filename

Much Appreciated
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,178
Members
453,021
Latest member
Justyna P

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