How do I get a folder to open with latest file.

ghrek

Active Member
Joined
Jul 29, 2005
Messages
427
Hi

I have a folder that has approx 14 workbooks in and a shortcut button on a different workbook .

Im trying to find a way that I can click on the shortcut button and then it will go into the folder concerned and then open the latest file that has been created. I was advised that it poss open latest file that amended but may not be the latest one created but I dont need that and need the latest file in the folder regardless of when others amended or updated.

Can anyone assist?

Thanks
 

Excel Facts

What is the last column in Excel?
Excel columns run from A to Z, AA to AZ, AAA to XFD. The last column is XFD.
This should open the latest created, regardless of modifications, xls file in your folder.

Code:
Dim fso As FileSystemObject, fldr As Scripting.Folder, fle As Scripting.File
Dim dte As Double, myFile As File, wb As Workbook

Set fso = New FileSystemObject
Set fldr = fso.GetFolder("C:\Users\Steve\Desktop\New Folder")
For Each fle In fldr.Files
    If InStr(LCase(fle.Name), ".xls") > 0 Then
        If fle.DateCreated > dte Then
            Set myFile = fle
        End If
    End If
Next fle
If Not myFile Is Nothing Then Set wb = Workbooks.Open(myFile)
 
Last edited:
Upvote 0
Go to the vba window and check the checkbox for the Microsoft scripting runtime reference. Think its in tools-references off top of head
 
Upvote 0

Forum statistics

Threads
1,223,886
Messages
6,175,190
Members
452,616
Latest member
intern444

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