Adding names to a cell - application-defined or object-defined error

  • Thread starter Thread starter Chris
  • Start date Start date
C

Chris

I made my own user defined function to act as a test function for me
to try some stuff out in a sub that is being ran from a button.

My test function is

Function testFunc() As Integer
On Error GoTo errhandler
ActiveWorkbook.Names.Add Name:="ZOMGNAME", RefersTo:="=Sheet1!X20"
testFunc = 1
errhandler:
MsgBox Err.Description
End Function

The error I get is application-defined or object-defined error

The function exists in the workbooks Module1 module

Why am I getting the error?

Thanks in advance
 
You don't have any cell that contains a formula that tries to use this function,
right?

I couldn't duplicate the error as long as I had a worksheet named Sheet1 in my
activeworkbook.

ps. You may want to avoid the errhandler if there is no error.

Option Explicit
Function testFunc() As Integer
On Error GoTo errhandler
ActiveWorkbook.Names.Add Name:="ZOMGNAME", RefersTo:="=Sheet1!X20"
testFunc = 1
Exit Function
errhandler:
MsgBox Err.Description
End Function
 
Back
Top