View Single Post
  #10   Report Post  
Posted to microsoft.public.excel.programming
Manuelauch Manuelauch is offline
external usenet poster
 
Posts: 6
Default VBA codes to get dates of files in a folder

Thank you for your response.

"Jim Cone" wrote:


The Microsoft Scripting Runtime (scrrun.dll) is included with all current versions
of Windows. You can set a reference to it in Tools | References in the VBE or
use late binding. An example...
'---
Sub LatestFile()
'Jim Cone - San Francisco, USA - June 02, 2005
'Displays the latest file name in the strPath folder.

Dim objFSO As Object
Dim objFolder As Object
Dim objFile As Object
Dim strPath As String
Dim strName As String
Dim varDate As Variant

' Specify the folder...
strPath = "C:\Program Files\Microsoft Office\Office\Library"
' Use Microsoft Scripting runtime.
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFolder = objFSO.GetFolder(strPath)

' Check date on each file in folder.
For Each objFile In objFolder.Files
If objFile.DateLastModified varDate Then
varDate = objFile.DateLastModified
strName = objFile.Name
End If
Next 'objFile

' Display file name in message box.
MsgBox strName & " - is latest file - " & varDate

Set objFSO = Nothing
Set objFolder = Nothing
Set objFile = Nothing
End Sub
'---
Also see...
http://www.microsoft.com/downloads/d...DisplayLang=en
--
Jim Cone
San Francisco, USA
http://www.realezsites.com/bus/primitivesoftware
(Excel Add-ins / Excel Programming)





"Manuelauch"
wrote in message
Jim Cone
I do not understand what you mean by (Scripting) FileSystemObject