Consulting

Results 1 to 7 of 7

Thread: Solved: Detecting Last Time File Was Opened

  1. #1
    VBAX Expert
    Joined
    Feb 2010
    Posts
    696
    Location

    Solved: Detecting Last Time File Was Opened

    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?

  2. #2
    VBAX Guru mancubus's Avatar
    Joined
    Dec 2010
    Location
    "Where I lay my head is home" :D
    Posts
    2,644
    check this out:
    http://www.vbaexpress.com/forum/showthread.php?t=18942

    but not sure if it helps...
    PLS DO NOT PM; OPEN A THREAD INSTEAD!!!

    1) Posting Code
    [CODE]PasteYourCodeHere[/CODE]
    (or paste your code, select it, click # button)

    2) Uploading File(s)
    Go Advanced / Attachments - Manage Attachments / Add Files / Select Files / Select the file(s) (multiple files can be selected while holding Ctrl key) / Upload Files / Done
    Replace company specific / sensitive / confidential data. Include so many rows and sheets etc in the uploaded workbook to enable the helpers visualize the data and table structure. Helpers do not need the entire workbook.

    3) Testing the Codes
    always back up your files before testing the codes.

    4) Marking the Thread as Solved
    from Thread Tools (on the top right corner, above the first message)

  3. #3
    [vba]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[/vba]
    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.
    Toby
    Portland, Oregon

  4. #4
    VBAX Expert
    Joined
    Feb 2010
    Posts
    696
    Location
    Quote Originally Posted by mancubus
    check this out:
    http://www.vbaexpress.com/forum/showthread.php?t=18942

    but not sure if it helps...
    Thanks. I'll check it out.

  5. #5
    VBAX Expert
    Joined
    Feb 2010
    Posts
    696
    Location
    Quote Originally Posted by AirCooledNut
    [vba]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[/vba]
    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.

  6. #6
    Knowledge Base Approver VBAX Wizard
    Joined
    Apr 2012
    Posts
    5,645
    several methods:

    [vba] 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

    [/vba]

  7. #7
    VBAX Expert
    Joined
    Feb 2010
    Posts
    696
    Location
    Quote Originally Posted by snb
    several methods:

    [vba] 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

    [/vba]
    Thanks for the additional insight.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •