indi visual
Member
I am in need of a tweak of the code below that finds the most recently modified file and simply opens the folder it resides in (a yes no pop up box is not necessary).
The file itself doesn't need to be opened (only the folder that it's in).
[pre]<br />
Sub test()<br />
Dim myDir As String, fn As String, a(), n As Long, myFile As String<br />
Dim myDate As Date, temp As Date<br />
myDir = "W:"<br />
fn = Dir(myDir & "*.xls"<br />
Do While fn <> ""<br />
temp = CreateObject("Scripting.FileSystemObject".GetFile(myDir & "" & fn).DateLastModified<br />
If myDate = 0 Then<br />
myDate = temp : myFile = myDir & "" & fn<br />
Else<br />
If myDate < temp Then myDate = temp : myFile = myDir & "" & fn<br />
End If<br />
fn = Dir<br />
Loop<br />
If Len(myFile) Then<br />
If vbYes = MsgBox("File Name : " & myFile & vbLf & _<br />
"Last modified on : " & myDate, vbYesNo) Then<br />
Workbooks.Open(myDir & "" & myFile)<br />
End If<br />
End If<br />
End Sub<br />
[/pre]
-I will only post this question here exclusively-
The file itself doesn't need to be opened (only the folder that it's in).
[pre]<br />
Sub test()<br />
Dim myDir As String, fn As String, a(), n As Long, myFile As String<br />
Dim myDate As Date, temp As Date<br />
myDir = "W:"<br />
fn = Dir(myDir & "*.xls"<br />
Do While fn <> ""<br />
temp = CreateObject("Scripting.FileSystemObject".GetFile(myDir & "" & fn).DateLastModified<br />
If myDate = 0 Then<br />
myDate = temp : myFile = myDir & "" & fn<br />
Else<br />
If myDate < temp Then myDate = temp : myFile = myDir & "" & fn<br />
End If<br />
fn = Dir<br />
Loop<br />
If Len(myFile) Then<br />
If vbYes = MsgBox("File Name : " & myFile & vbLf & _<br />
"Last modified on : " & myDate, vbYesNo) Then<br />
Workbooks.Open(myDir & "" & myFile)<br />
End If<br />
End If<br />
End Sub<br />
[/pre]
-I will only post this question here exclusively-