Search code examples
excelvbauser-defined-functionsexcel-addins

Using an UDF from an Add-in in another UDF


I've got an Add-in loaded in Excel which contains all my UDF's.
One of them is called Pythagoras. It is defined like:

Function Pythagoras(Optional side1, Optional side2, Optional hypotenusa)
If Not (IsMissing(side1)) And Not (IsMissing(side2)) Then
    Pythagoras = Sqr(side1 ^ 2 + side2 ^ 2)
Else
    If Not (IsMissing(side1)) And Not (IsMissing(hypotenusa)) Then
        Pythagoras = Sqr(hypotenusa ^ 2 - side1 ^ 2)
    Else
        If Not (IsMissing(side2)) And Not (IsMissing(hypotenusa)) Then
            Pythagoras = Sqr(hypotenusa ^ 2 - side2 ^ 2)
        Else
            Pythagoras = "Please supply two arguments."
        End If
    End If
End If
End Function

It shows up nicely in the "User Defined"-list and works perfect.

However, my problem is that I can't seem to find out how I can use it within another UDF.
Is this something which just isn't possible? If it is possible, how can I do this?


Solution

  • It's a little messy to look at, but you could refer to the function this way:

    retval = Application.Run("'NAME_OF_YOUR_ADDIN.xlam'!Pythagoras", s1, s2, ha)