Retrieve latest template from folder

eager_vba_novice

New Member
Joined
Mar 29, 2006
Messages
5
Hello all :)

My boss stores the quote template in a folder. Each file in the folder is named the same except for a R and revision number at the end of the filename, ie...R1, R2...etc. The current revision if R19.

I have a macro button that opens the latest template but I have to manually change the code to match the rev.

Is there a way to retrieve the latest template revision without knowing the revision number?

Thank you and hope you're having a great day!
 

Excel Facts

Whats the difference between CONCAT and CONCATENATE?
The newer CONCAT function can reference a range of cells. =CONCATENATE(A1,A2,A3,A4,A5) becomes =CONCAT(A1:A5)
Try this, with the folder path and file name changed to suit.
Code:
    Dim n As Integer
    Dim latestFile As String
    
    n = 0
    Do
        n = n + 1
    Loop Until Dir("C:\path\to\folder\Template R" & n & ".xlsx") = vbNullString
    latestFile = "C:\path\to\folder\Template R" & n - 1 & ".xlsx"
    Debug.Print latestFile
 
Upvote 0

Forum statistics

Threads
1,215,073
Messages
6,122,976
Members
449,095
Latest member
Mr Hughes

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