Open Last Modified File form Location
A slightly another approach:
Sub OpenLastModifiedFilewithinFolder()
On Error Resume Next
With Application.FileSearch
.LookIn = "C:" : .Filename = "*.XLS*"
If .Execute(SortBy:=msoSortByFileName, SortOrder:=msoSortOrderAscending)
0 Then
For FF = 1 To .FoundFiles.Count
If FileDateTime(.FoundFiles(FF)) LastModDate Then
LastModDate = FileDateTime(.FoundFiles(FF))
LMF = .FoundFiles(FF)
End If
Next
End If
End With
Workbooks.Open (LMF)
End Sub
============
Micky
"מיכאל (מיקי) אבידן" wrote:
In order to OPEN(!) the last modified file he'll need the command listed below:
Workbooks.Open (strLMFile)
Micky
"Jacob Skaria" wrote:
One way using Dir()..
Sub LastModifiedFilewithinFolder()
Dim strFile As String, strFolder As String
Dim dtLast As Date, strLMFile As String
strFolder = "C:\"
'strFolder = "C:\Users\Glenys\Desktop\Glen_Macro\"
strFile = Dir("c:\*.*", vbNormal)
Do While strFile < ""
If FileDateTime(strFolder & strFile) dtLast Then
dtLast = FileDateTime(strFolder & strFile)
strLMFile = strFolder & strFile
End If
strFile = Dir
Loop
MsgBox "Last Modified file is : " & strLMFile
End Sub
--
Jacob
"Kam" wrote:
Hi,
I have one folder, which has 20 files & I want macro to open last modified
file in that folder. Is this can be done??
File Path: C:\Users\Glenys\Desktop\Glen_Macro\
Best Regards,
Kam.
|