View Single Post
  #3   Report Post  
Posted to microsoft.public.excel.misc
מיכאל (מיקי) אבידן מיכאל (מיקי) אבידן is offline
external usenet poster
 
Posts: 561
Default Open Last Modified File form Location

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.