Excel, BuiltinDocumentProperties, Last Save Time

User avatar
SammyB
StarLounger
Posts: 93
Joined: 04 Mar 2010, 16:32

Excel, BuiltinDocumentProperties, Last Save Time

Post by SammyB »

I was trying to figure out how to get the date that a workbook was saved into a date variable. The documentation is severely lacking :hairout: , so I thought that I would post this example of how to use Document Properties get the last save time of a workbook:

Code: Select all

Sub testDP()
    Dim dp As DocumentProperty, d As Date
    Set dp = ActiveWorkbook.BuiltinDocumentProperties("Last Save Time")
    d = dp.Value
    MsgBox "Workbook was last saved " & d
End Sub

User avatar
SammyB
StarLounger
Posts: 93
Joined: 04 Mar 2010, 16:32

Re: Excel, BuiltinDocumentProperties, Last Save Time

Post by SammyB »

By the way, this does not work if the workbook is a csv. When you create the csv, you will have to save it as an xlsx

User avatar
HansV
Administrator
Posts: 78474
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: Excel, BuiltinDocumentProperties, Last Save Time

Post by HansV »

SammyB wrote:
07 Jun 2023, 06:09
By the way, this does not work if the workbook is a csv. When you create the csv, you will have to save it as an xlsx
That makes sense - a .csv file is a plain text file, it does not have BuiltinDocumentProperties.
Best wishes,
Hans

User avatar
SpeakEasy
4StarLounger
Posts: 550
Joined: 27 Jun 2021, 10:46

Re: Excel, BuiltinDocumentProperties, Last Save Time

Post by SpeakEasy »

You might also want to consider the VBA function FileDateTime - which will work with any file type, including CSVs

User avatar
SammyB
StarLounger
Posts: 93
Joined: 04 Mar 2010, 16:32

Re: Excel, BuiltinDocumentProperties, Last Save Time

Post by SammyB »

Ah, that was a much better solution, SpeakEasy. Thanks! Here is a sample test routine:

Code: Select all

Sub testSavedTime2()
    Dim wb As Workbook, d As Date, s As String
    For Each wb In Application.Workbooks
        If right(wb.Name, 4) = ".csv" Then
            s = wb.FullName
            d = FileDateTime(s)
            MsgBox wb.Name & " was last saved " & d
        End If
    Next wb
End Sub