Can anyone advise me how to add a formula to an excel worksheet that will
display the most recent "modified" date? Please note I am familiar with NOW
and TODAY() functions - instead, I am interested in displaying only the date
the file was last saved. The NOW and TODAY() functions update every time the
file is opened and that is not what I want.

Signature
CC
JLatham - 24 Oct 2007 21:35 GMT
I don't know that there's a worksheet function to provide that information,
but you can create your own! Called a 'User Defined Function', or UDF.
Public Function GetModifiedDate() As Date
Dim fs, f
Application.Volatile
Set fs = CreateObject("Scripting.FileSystemObject")
Set f = fs.GetFile(ThisWorkbook.FullName)
GetModifiedDate = f.DateLastModified
Set f = Nothing
Set fs = Nothing
End Function
To use this, open the workbook and press [Alt]+[F11] and then choose Insert
| Module in the VB Editor window. copy and paste the above code into the
code area and close the window.
Next, in the cell where you want the last modifed date to show up put this
formula:
=GetModifiedDate()
NOTE: in order for this to work, the workbook must have been saved to disk
at least once.
ANOTHER NOTE: this may not automatically update. The Application.Volatile
statement tells it to update whenever any new calculation takes place on that
worksheet, but if no new calculations take place, then it won't update
either. You may have to press [F9] to get the latest date for the file.
> Can anyone advise me how to add a formula to an excel worksheet that will
> display the most recent "modified" date? Please note I am familiar with NOW
> and TODAY() functions - instead, I am interested in displaying only the date
> the file was last saved. The NOW and TODAY() functions update every time the
> file is opened and that is not what I want.
JLatham - 24 Oct 2007 21:45 GMT
Probably a much better way!
Public Function GetModifiedDate() As Date
Application.Volatile
GetModifiedDate = _
ThisWorkbook.BuiltinDocumentProperties("Last Save Time")
End Function
do same as before - copy it into the workbook (delete previous function
w/same name if you already copied it into the workbook), then set up the
formula in the cell where you want the data/time of last modification to show
up.
> Can anyone advise me how to add a formula to an excel worksheet that will
> display the most recent "modified" date? Please note I am familiar with NOW
> and TODAY() functions - instead, I am interested in displaying only the date
> the file was last saved. The NOW and TODAY() functions update every time the
> file is opened and that is not what I want.
Curious Cat - 29 Oct 2007 02:59 GMT
Thanks, I'll give this a try!

Signature
CC
> Probably a much better way!
>
[quoted text clipped - 14 lines]
> > the file was last saved. The NOW and TODAY() functions update every time the
> > file is opened and that is not what I want.
Chip Pearson - 24 Oct 2007 22:37 GMT
Try the following code:
Public Function LastSaved(Optional FileName As String) As Variant
If FileName = vbNullString Then
If ThisWorkbook.Path = vbNullString Then
LastSaved = CVErr(xlErrValue)
Else
LastSaved = FileDateTime(ThisWorkbook.FullName)
End If
Else
If Dir(FileName, vbNormal) = vbNullString Then
LastSaved = CVErr(xlErrValue)
Else
LastSaved = FileDateTime(FileName)
End If
End If
End Function
You can call it from a cell with =LastSaved()

Signature
Cordially,
Chip Pearson
Microsoft MVP - Excel, 10 Years
Pearson Software Consulting
www.cpearson.com
(email on the web site)
> Can anyone advise me how to add a formula to an excel worksheet that will
> display the most recent "modified" date? Please note I am familiar with
[quoted text clipped - 4 lines]
> the
> file is opened and that is not what I want.
Curious Cat - 29 Oct 2007 02:59 GMT
Thanks, Chip. I'll give this a shot.

Signature
CC
> Try the following code:
>
[quoted text clipped - 24 lines]
> > the
> > file is opened and that is not what I want.