access file based on last saved date/time

S

SteveDB1

Hello folks.
I'm trying to develop a multi-stage macro that will access a group of files,
and look at the last saved date. If that date is more recent than the file
the macro is calling from, I want to open, and then copy a portion of the
second file into the first.
We've purchased the WROX Excel 2007 VBA programmer's reference manual, but
I'm not able to readily identify the information I'm seeking to accomplish
the above.

So, at this point, I want to accomplish the following:
1- have the code to look at the save date in the properties of fileB.
2- if that date is more recent than the last save date of fileA, open fileB.

does anoyone know where I can look in the programmer's reference book to
learn more on how to perform this?
Or, how to do this?
Thank you.
Best.
 
J

Joel

Sub ShowFolderInfo()
Dim fs, myfolder, myfiles

Const MyPath = "c:\temp"



Set fs = CreateObject("Scripting.FileSystemObject")

Filename = UCase(ThisWorkbook.Name)
If Right(Filename, 3) <> "XLS" Then
MsgBox ("File does not exist because Wrokbook was not saved")
End If

Set ThisFile = fs.getfile(ThisWorkbook.Name)
Thisdate = ThisFile.datelastmodified

Set myfolder = fs.GetFolder(MyPath)


For Each Filename In myfolder.Files
If UCase(Right(Filename.Name, 3)) = "XLS" Then

datemodified = Filename.datelastmodified

If datemodified > Thisdate Then
'enter your code here
End If
End If
Next Filename

End Sub
 

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