Open a Work Book where the name is variable

Yachrishere

New Member
Joined
May 6, 2019
Messages
6
Hi.
I am looking for a way to open a work book that is in a constantly named folder but the name may alter.
i.e. Roof V4.1.xlsm but a later version could be Roof V5.6.xlsm

The path to the folder won't change, just the file name.
I have tried to make it a string so I can use a wild card but it doesn't recognise it as I get a run time error 1004.

Code:
MyFile = Dir("\Roof V*")
    Workbooks.Open Filename:=(ActiveSheet.Range("E11").Value & "\Quoting Files" & MyFile)
[Code]

Cell E11 has the path so it's value works, then the folder "\Quoting Files" is correct but it wont accept [U]MyFile

[/U]Any help on this would be greatly appreciated.
 

Excel Facts

Repeat Last Command
Pressing F4 adds dollar signs when editing a formula. When not editing, F4 repeats last command.
Try using the path in Dir.
Code:
Dim strPath As String

    strPath = ActiveSheet.Range("E11").Value & "\Quoting Files\"

    MyFile = Dir(strPath & "Roof V*"

    If Len(MyFile)<>0 Then
        Workbooks.Open strPath  & MyFile
    End If
 
Upvote 0

Forum statistics

Threads
1,223,984
Messages
6,175,786
Members
452,670
Latest member
nogarth

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