PDA

View Full Version : Get Last Accessed Date/time



av8tordude
04-10-2008, 09:06 AM
Below the code allows me to get the last modified, but I want to get the last time the file was access. How do get the "Last Accessed" Date/Time?

If CurrentTime < ActiveWorkbook.BuiltinDocumentProperties("Last Save Time") Then
MsgBox "Date Moved"

Bob Phillips
04-10-2008, 09:46 AM
You would have to save that last accessed time somewhere and retrieve that, or you could use FSO on the disk file.

av8tordude
04-10-2008, 09:58 AM
You would have to save that last accessed time somewhere and retrieve that, or you could use FSO on the disk file.

Ok. I would assume I would have to place this in a cell. If so, how do I achieve that?

Also, the FSO seems viable as well. How about it?

Bob Phillips
04-10-2008, 10:00 AM
Dim fso As Object

Set fso = CreateObject("Scripting.FilesystemObject")
MsgBox fso.getfile("C:\test\Bob test.xls").datelastaccessed
Set fso = Nothing

av8tordude
04-10-2008, 10:05 AM
Dim fso As Object

Set fso = CreateObject("Scripting.FilesystemObject")
MsgBox fso.getfile("C:\test\Bob test.xls").datelastaccessed
Set fso = Nothing


Thanks again. Only problem I see I will run into, if the file is changed/moved to a different location, it would cause an error. is there any other way to achieve this?

mdmackillop
04-10-2008, 10:22 AM
You could add it to a Range Name, but the Save may be an issue.

Private Sub Workbook_Open()
With ActiveWorkbook
On Error Resume Next
.Names("LastAccess").Delete
.Names.Add Name:="LastAccess", RefersToR1C1:="=""" & Format(Now(), "DD/MM/YY hh:mm:ss") & """"
.Save
End With
End Sub

Bob Phillips
04-10-2008, 10:25 AM
If the file is moved, you code will have problems with it whatever, not just this bit.

Norie
04-10-2008, 10:37 AM
This is cross-posted and closed here (http://www.ozgrid.com/forum/showthread.php?t=88137).

mdmackillop
04-10-2008, 10:40 AM
Thanks Norie