+ Reply to Thread
Results 1 to 4 of 4

VBA code for xlsm file's Last Modified Date/Time

Hybrid View

  1. #1
    Registered User
    Join Date
    02-20-2012
    Location
    Chicago, Illinois
    MS-Off Ver
    Excel 2010
    Posts
    25

    VBA code for xlsm file's Last Modified Date/Time

    I inherited a spreadsheet that contains the following function:

    Function MyStamp()
    Application.Volatile
    MyStamp = FileDateTime(ThisWorkbook.FullName)
    End Function
    Trouble is, this is NOT showing the spreadsheet's Last Modified date.

    For example, I took a file that was emailed to me. I copied it to my C: drive on 3/2/12 16:57. That's the file date/time that's showing up in the cell where the function is called.

    However, if (in Excel 2010) I open the file from my C: drive, then go to File / Info / Related Dates, it correctly shows the Last Modified date of the file, which is 2/15/2012 2:57 PM (not the 3/2 of the file on my C: drive).

    How do I write code to show the actual Last Saved Date of the file?

    Thanks in advance.

  2. #2
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2010, 2019
    Posts
    40,689

    Re: VBA code for xlsm file's Last Modified Date/Time

    Maybe ...

    Function MyStamp()
        Static oFSO As Object
        
        If oFSO Is Nothing Then
            Set oFSO = CreateObject("Scripting.FileSystemObject")
        End If
        
        MyStamp = oFSO.GetFile(ThisWorkbook.FullName).DateLastModified
    End Function
    Entia non sunt multiplicanda sine necessitate

  3. #3
    Registered User
    Join Date
    02-20-2012
    Location
    Chicago, Illinois
    MS-Off Ver
    Excel 2010
    Posts
    25

    Re: VBA code for xlsm file's Last Modified Date/Time

    Thank you shg.

    I tried that function, and I'm getting a #NAME? error. Hmmmm...

    I'm looking and looking... I don't see why it's failing...

    Ciao

  4. #4
    Forum Expert
    Join Date
    07-20-2011
    Location
    Mysore, India.
    MS-Off Ver
    Excel 2019
    Posts
    8,710

    Re: VBA code for xlsm file's Last Modified Date/Time

    Use Workbook_BeforeClose event with the following code.

    Sheets("Sheet1").range"AA1"="Last date modified " & NOW()

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1