use Wildcard in file name

doriannjeshi

Active Member
Joined
Apr 5, 2015
Messages
301
Office Version
  1. 365
Platform
  1. Windows
Hello,

I need to create a macro that copies data from a workbook that the name will change and a fixed sufix i.e: 22034202_name.xls
how should I go with using the wildcard in the file name?
 

Excel Facts

Will the fill handle fill 1, 2, 3?
Yes! Type 1 in a cell. Hold down Ctrl while you drag the fill handle.
In your example, "22034202_" is a constant, "name" is a variable and ".xls" is a constant?
 
Upvote 0
Don't be so stingy. Supply information. I promise, I won't tell anybody!!!
Are both workbooks open? You could have 12 workbooks open and you need one particular one.
Is one open, with the code I assume, and the other one needs to be opened from a Folder?
It could even be possible that both workbooks are closed and you run the code from a third, although I don't think that that is what you are doing.
 
Upvote 0
Thanks for helping,

this one 2034202_name.xls needs to be opened from a folder
Yes the one with the code is open and needs to copy cells from 2034202_name.xls
i.e copy from sheet1 of 2034202_name.xls paste to sheet2 of test.xlsm (the one with the code)
possible ?
 
Upvote 0
Code:
Sub Like_So()
Dim fn As String
fn = Dir("C:\Folder Name\Sub Folder Name\" & "*" & "_name.xls")
Workbooks.Open "C:\Folder Name\Sub Folder Name\" & fn
End Sub
 
Upvote 0
Solution
1724625351883.png
 
Upvote 0
In Post #1 it is an ".xls" extension. In Post #7 it is an ".xlsx" extension.
I am sure you don't have a Folder named "Folder Name" and a Sub Folder inside that Folder named "Sub Folder Name"!!!!!
Change to required.
 

Attachments

  • Folder Name.jpg
    Folder Name.jpg
    6.2 KB · Views: 13
Last edited:
Upvote 1
and to open two files same folder with this method ?
possible to give command to copy from opened file with wildcard name ?
 
Upvote 0
It will open the first found file.

If you have not too many files, I would look at a UserForm with Listbox populated with filenames where you can select from.
 
Upvote 1

Forum statistics

Threads
1,223,893
Messages
6,175,244
Members
452,622
Latest member
Laura_PinksBTHFT

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