Monday, September 3, 2012

Document Properties


Sometimes there is a need/requirement to get the Document properties in particular the "Last Saved Date", "Last Saved Time", "Last Saved By", "Author", etc...

There are various codes that can be used, however I feel that using the code below is a lot easier as only needs to be written once:

Function DocProps(prop As String)
     '-----------------------------------------------------------------
    Application.Volatile
    On Error GoTo err_value
    DocProps = ActiveWorkbook.BuiltinDocumentProperties _
    (prop)
    Exit Function
err_value:
    DocProps = CVErr(xlErrValue)
End Function


Off course that we do need now to indentify the cells with what is required from the code so in your book and in the desired cell just enter the following:

  • Last Saved Date =DocProps("Last Save Time") format as dd/mm/yy
  • Last Saved Time =DocProps("Last Save Time") format as hh:mm:ss
  • Last Saved By =DocProps("Last Author") format as General
  • Author =DocProps("Author") format as General