Open file with latest date

Ludde7172

New Member
Joined
Oct 15, 2021
Messages
2
Office Version
  1. 365
Hello All,

I have a problem that I do not how to solve. I would like to open the latest date with a file that contains the work document. There will be several files with the name document, i.e document(1), document(2) ...

Today I use this code:

myPath = ThisWorkbook.Path & "\"
fname = Dir(myPath & "Kollektiv*")

If fname <> "" Then
Set wb = Workbooks.Open(myPath & fname)
End If

/L
 

Excel Facts

When did Power Query debut in Excel?
Although it was an add-in in Excel 2010 & Excel 2013, Power Query became a part of Excel in 2016, in Data, Get & Transform Data.
Try: (change the path)

VBA Code:
Sub jec()
a = Split(CreateObject("wscript.shell").Exec("cmd /c Dir  ""C:\Users\xx\Documents\xxx\xxx\Kollektiv*"" /b/t:a/o:d/s").StdOut.ReadAll, vbCrLf)
If IsArray(a) Then Workbooks.Open (a(0))
End Sub
 
Upvote 0
Maybe better to read:
This code opens the file which has the latest "last opened" date

VBA Code:
Sub jec()
 myPath = ThisWorkbook.Path & "\Kollektiv*"
 a = Split(CreateObject("wscript.shell").Exec("cmd /c Dir  """ & myPath & """  /b/t:a/o:d/s").StdOut.ReadAll, vbCrLf)
 If IsArray(a) Then Workbooks.Open a(0)
End Sub
 
Last edited:
Upvote 0
Hmm where does it error?
 
Upvote 0

Forum statistics

Threads
1,215,425
Messages
6,124,824
Members
449,190
Latest member
rscraig11

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