Wild Card in opening a file

Billy C

Board Regular
Joined
Aug 26, 2005
Messages
52
I am attempting to open a file where the first few characters are repeated each week however the remainder of the file name changes each time. There will only be one file in this directory that begins with the static characters (030A rtofw2) so I was intending to use a wild card * to substitute for the trailing file name change

When I use the following code the file opens
Workbooks.Open (MyPath1 & "\" & "030A rtofw2_chamill1_20081105_09h38m25s_030a_468e638a1dd211b2a298f5f2f3e4e3b1_01.XLW")

When I try to use a * wild card, the file fails to open
Workbooks.Open (MyPath1 & "\" & "030A rtofw2 *.XLW")

Is this because I am trying to open an XLW or is it the _ , When I try to use a * wild card, the file fails to open
Can any one help solve this, please.
 

Excel Facts

Ambidextrous Undo
Undo last command with Ctrl+Z or Alt+Backspace. If you use the Undo icon in the QAT, open the drop-down arrow to undo up to 100 steps.
Hi Billy,

Try something along the lines of:
Code:
Public Sub OpenMyFiles()
Dim strFold As String
Dim strFName As Variant
Dim oWB As Workbook
  strFold = "C:\Users\Billy\Documents\"
  strFName = Dir(strFold & "030A rtofw2*.xlw", vbNormal)
  While strFName <> ""
    Set oWB = Workbooks.Open(strFold & strFName)
'   Put your post-open processing here
    oWB.Close ' Delete this line if you want to keep the wb open
    strFName = Dir()
  Wend
End Sub
Cheers
 
Upvote 0
Whether there is one file or many, the code I posted can be used. If there's only one matching the filename specification, then only one will be found and processed.

Cheers
 
Upvote 0

Forum statistics

Threads
1,225,378
Messages
6,184,621
Members
453,249
Latest member
gmazee

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