VBA code to open most recent file saved in folder

arecube

New Member
Joined
Feb 24, 2006
Messages
46
How can I get VBA code to locate and open only the latest edition of an .xls or .doc file within a folder ?

We use Excel 2003

The Excel files are in one path and the Word files in another.

Almost daily there is a "latest edition" of files placed in a folder along with all of their predecessor file editions. At times there are 2 or 3 revisions within one day.

To do this manually I double-click on the "Modified" column heading to bring the latest file to the top and then I open it. Once open, I input a header, search for certain numbers or text and then print the page that meets the "find" criteria.
 
Thanks John for the nearly instant reply and it should be a great start.


I have the macro to open the file in folder but it opens the old file instead of latest.

Could you please assist.

Sub Macro6()
FolderName = "H:\Fire Code"
If Right(FolderName, 1) <> Application.PathSeparator Then FolderName = FolderName & Application.PathSeparator
Fname = Dir(FolderName & "*.xlsx")
With Workbooks.Open(FolderName & Fname)
End With
End Sub
 
Upvote 0

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