Consulting

Results 1 to 9 of 9

Thread: Get Last Accessed Date/time

  1. #1

    Get Last Accessed Date/time

    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"

  2. #2
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    You would have to save that last accessed time somewhere and retrieve that, or you could use FSO on the disk file.
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  3. #3
    Quote Originally Posted by xld
    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?

  4. #4
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    [vba]

    Dim fso As Object

    Set fso = CreateObject("Scripting.FilesystemObject")
    MsgBox fso.getfile("C:\test\Bob test.xls").datelastaccessed
    Set fso = Nothing
    [/vba]
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  5. #5
    Quote Originally Posted by xld
    [vba]

    Dim fso As Object

    Set fso = CreateObject("Scripting.FilesystemObject")
    MsgBox fso.getfile("C:\test\Bob test.xls").datelastaccessed
    Set fso = Nothing
    [/vba]
    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?

  6. #6
    Administrator
    VP-Knowledge Base
    VBAX Grand Master mdmackillop's Avatar
    Joined
    May 2004
    Location
    Scotland
    Posts
    14,489
    Location
    You could add it to a Range Name, but the Save may be an issue.
    [VBA]
    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

    [/VBA]
    MVP (Excel 2008-2010)

    Post a workbook with sample data and layout if you want a quicker solution.


    To help indent your macros try Smart Indent

    Please remember to mark threads 'Solved'

  7. #7
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    If the file is moved, you code will have problems with it whatever, not just this bit.
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  8. #8
    VBAX Master Norie's Avatar
    Joined
    Jan 2005
    Location
    Stirling, Scotland
    Posts
    1,831
    Location
    This is cross-posted and closed here.

  9. #9
    Administrator
    VP-Knowledge Base VBAX Grand Master mdmackillop's Avatar
    Joined
    May 2004
    Location
    Scotland
    Posts
    14,489
    Location
    Thanks Norie
    MVP (Excel 2008-2010)

    Post a workbook with sample data and layout if you want a quicker solution.


    To help indent your macros try Smart Indent

    Please remember to mark threads 'Solved'

Posting Permissions

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