PDA

View Full Version : Solved: Detecting Last Time File Was Opened



Opv
09-28-2012, 11:59 AM
How would I access the file attributes for the active workbook in order to test whether the workbook has already been opened earlier during the same day?

mancubus
09-28-2012, 01:17 PM
check this out:
http://www.vbaexpress.com/forum/showthread.php?t=18942

but not sure if it helps...

AirCooledNut
09-28-2012, 01:25 PM
Option Explicit

Sub GetLastSavedDTStamp()
Dim wWB As Workbook

Set wWB = ActiveWorkbook

On Error Resume Next
Debug.Print wWB.BuiltinDocumentProperties.Item(12).Value
On Error Goto 0

Set wWB = Nothing
End Sub
The reason for the On Error... is because if the Value doesn't exist (not all will) then the code will throw an error.

Highlight the BuiltinDocumentProperties word and hit the F1 key in the VB Editor to get further help on this.

Opv
09-28-2012, 01:36 PM
check this out:
http://www.vbaexpress.com/forum/showthread.php?t=18942

but not sure if it helps...

Thanks. I'll check it out.

Opv
09-28-2012, 01:39 PM
Option Explicit

Sub GetLastSavedDTStamp()
Dim wWB As Workbook

Set wWB = ActiveWorkbook

On Error Resume Next
Debug.Print wWB.BuiltinDocumentProperties.Item(12).Value
On Error Goto 0

Set wWB = Nothing
End Sub
The reason for the On Error... is because if the Value doesn't exist (not all will) then the code will throw an error.

Highlight the BuiltinDocumentProperties word and hit the F1 key in the VB Editor to get further help on this.

Thanks. I'll play round with code. I think I can figure out a way to adapt the code to work for my purposes.

snb
09-30-2012, 04:03 AM
several methods:

c011 = FileDateTime(ThisWorkbook.FullName)

c111 = ThisWorkbook.BuiltinDocumentProperties(12)

c111 = ThisWorkbook.BuiltinDocumentProperties("last save time")

c211 = CreateObject("scripting.filesystemobject").getfile(ThisWorkbook.FullName).datelastmodified

c311 = CreateObject("shell.application").namespace(ThisWorkbook.Path & "\").Items.Item(ThisWorkbook.Name).ModifyDate

With CreateObject("shell.application").namespace(ThisWorkbook.Path & "\")
c411 = .getdetailsof(.Items.Item(ThisWorkbook.Name), 3)
End With

Opv
09-30-2012, 12:03 PM
several methods:

c011 = FileDateTime(ThisWorkbook.FullName)

c111 = ThisWorkbook.BuiltinDocumentProperties(12)

c111 = ThisWorkbook.BuiltinDocumentProperties("last save time")

c211 = CreateObject("scripting.filesystemobject").getfile(ThisWorkbook.FullName).datelastmodified

c311 = CreateObject("shell.application").namespace(ThisWorkbook.Path & "\").Items.Item(ThisWorkbook.Name).ModifyDate

With CreateObject("shell.application").namespace(ThisWorkbook.Path & "\")
c411 = .getdetailsof(.Items.Item(ThisWorkbook.Name), 3)
End With



Thanks for the additional insight.