ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Discussion (Misc queries) (https://www.excelbanter.com/excel-discussion-misc-queries/)
-   -   Trouble with UDF - getting #NAME error (https://www.excelbanter.com/excel-discussion-misc-queries/169946-trouble-udf-getting-name-error.html)

Joe M.

Trouble with UDF - getting #NAME error
 
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.

Dave Peterson

Trouble with UDF - getting #NAME error
 
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



Joe M. wrote:

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.


--

Dave Peterson


All times are GMT +1. The time now is 06:30 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com