i know of an open latest created file syntax but down't know what it is can anyone help also how do i specify the file path (where to look for the latest file)
This is how I would do the job. Be interestd to see your "latest created" syntax.
Code:
Sub FIND_NEWEST_FILE()
Dim MyFolder As String
Dim MyFileName As String
Dim MyDateTime As Date
Dim NewestFile As String
Dim NewestDateTime As Date
MyFolder = CurDir & "\"
'---------------------------
MyFileName = Dir(MyPath & "*.XLS")
Do While MyFileName <> ""
MyDateTime = FileDateTime(MyFolder & MyFileName)
If MyDateTime > NewestDateTime Then
NewestDateTime = MyDateTime
NewestFile = MyFileName
End If
MyFileName = Dir
Loop
'MsgBox (NewestFile & vbCr & NewestDateTime)
Workbooks.Open FileName:=MyFolder & NewestFile
End Sub
Yes. Well spotted. sorry for that. I did test it before posting and it worked correctly despite that.
Although the code does work on my machine, I think the line
MyFolder = CurDir
(which refers to the folder which is currently active.)
should be used instead of MyFolder = CurDir & "\"
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.