Evaluate File for Last Updated Date

J

jb_tenor1

I want to have my macro code determine the date a file was last updated and
then from there, decide whether or not to open it. What I don't know is how
to access the file's property that returns that date it was updated. If I
could just use an "If" statement to say something like this, in principle:

If Filename.DateUpdated >= Today() - 1 Then
Workbooks.Open Filename
End If

The goal is to only open files that have been updated within the last two
days. Is this possible?
 
G

Gord Dibben

Using document properties.

IF Filename.BuiltinDocumentProperties("Last Save Time") etc.


Gord Dibben MS Excel MVP
 
B

Barb Reinhardt

This should get you started

Option Explicit

Sub Test()
Dim FSO As Object
Dim RootFolder As Object
Dim myFolder As String
Dim File As Object

'define myFolder here

myFolder = "C:" 'Enter what you want
'Create FileSystemObject object
Set FSO = CreateObject("Scripting.FileSystemObject")

'Test if the folder exist and set RootFolder
If FSO.FolderExists(myFolder) = False Then
MsgBox myFolder & " doesn't exist"
Exit Sub
End If
Set RootFolder = FSO.GetFolder(myFolder)

For Each File In RootFolder.Files
Debug.Print File.Name, File.datelastmodified, File.datelastaccessed

Next File

Set FSO = Nothing

End Sub

IIRC, the BuiltInDocumentProperties can only be accessed once the file is
opened.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top