Trouble with UDF - getting #NAME error

J

Joe M.

I created the following UDF in order to show the last saved date:

Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As Boolean)
ThisWorkbook.Names.Add Name:="LastSaved", _
RefersToR1C1:="=""" & _
Format(Now, "mmm-dd-yyyy hh:mm") & """"
End Sub

When I enter in a cell =lastsaved or lastsaved() I get the error #NAME. What
am I doing wrong?

Thanks,
Joe M.
 
D

Dave Peterson

Did you put the code under the ThisWorkbook module?

Did you save the workbook at least onced so the event would fire and the name
would be created?

Did you ever have a function/name/module name called "LastSaved" in the
troublesome workbook?

Since you're refering to a name, you don't want the () in your formula.

Just use:
=LastSaved
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top