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

Add Bullets to Range
Select range. Press Ctrl+1. On Number tab, choose Custom. Type Alt+7 then space then @ sign (using 7 on numeric keypad)
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,215,219
Messages
6,123,689
Members
449,117
Latest member
Aaagu

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