Tom's Guide | Tom's Hardware | Tom's Games
![]() |
![]() |
![]() |
I created a UDF to put the "date last saved" in a cell in my spread sheet, as follows:
Function DateLastSaved(property as string)
DateLastSaved = ActiveWorkbook.BuiltinDocumentProperties(property)
End Function
I then set the formula, 'DateLastSaved=("Last Save Time")' in the cell inwhich I want the date to appear. It appeared to work fine, once (when I entered it).
The function only seems to work when I enter it in the cell. I save my file, changed the system date, re-opened the spread sheet and it contained the correct date. I altered a cell and save the file again. The date didn't change in the "date last saved" cell. I closed the spreadsheet and re-opened it. Again the date did not change. I selected the cell and re-rentered the function - the date changed. I must be missing something in my function? Can anyone tell me what I'm missing?
Thanks,
Tom

Stuff like this is a bit awkward, because xl doesn't know which properties you have in a UDF (since you could potentially have infinite ones) and so it doesn't assume it needs to recalculate them.
This is sensible, because if you send the sheet to someone who doesn't have the function (say its an add-in) then they don't automatically lose all UDF data.
The simplest solution to the problem this is causing you is to force it to re-input your cell value as you save it. (Either with or without a UDF)Insert a module and use a macro like this:
Private Sub Workbook_BeforeClose(varX As Boolean)
Sheets("SheetName").Range("A1") = "=FormulaHere"
End Suband either use the FormulaHere part to enter your UDF formula, or just to insert the current time/date.
Hope that helps
Tom

Tom, Thanks for your thoughts. Wouldn't you solution change the date every time the spreadsheet was closed? I don't want that to happen. I only want to change that date when the file is saved. The spread sheet is used to calculate customer estimates, so, is often opened to look at data only. The client wishes the date to be the last time it was modified and save.
Thanks for your time,
Tom

I'm not sure that the net effect is any different - but I guess its probably safer to use this:
Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As Boolean)
Sheets("Sheet1").Range("A1") = Now
End Sub
Make sure that you put the code in the workbook module. It won't work anywhere else.Cheers
Tom

![]() |
Retrieving text box behin...
|
Excel 2000 Errors
|

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.
| Ads by Google |