Excel VBA: ¿es posible crear funciones personalizadas con methods personalizados?

A lo que me refiero es, por ejemplo, cómo puedes hacer:

Range().Select 

Donde "Range ()" es la function, y "Select" es el método.

Por ejemplo, si tuviera una function, quería tomar tres dobles que representan las longitudes laterales de un triángulo y escupir el ángulo más grande en radianes de grados.

 Public Function getAngle(a as Double, b as Double, c as Double) .degrees = 'some equation to determine degrees as a double .rads = 'some equation to determine radians as a string End Function 

Por lo tanto, obtendría los siguientes resultados:

getAngle (3, 4, 5) .degrees: 90.0

getAngle (3, 4, 5) .rads: "0.5π"

Crea una class, para este nombre de ejemplo, clsTrig.

 Option Explicit '/ Class Name : clsTrig Private m_ddegrees As Double Private m_drads As Double Public Property Get degrees() As Double degrees = m_ddegrees End Property Public Property Let degrees(val As Double) m_ddegrees = val End Property Public Property Get rads() As Double rads = m_drads End Property Public Property Let rads(val As Double) m_drads = val End Property Public Function doCalc(a1 As Double, a2 As Double) As Double '/ You do the math here. This is just a sample and not actual trigonometery m_ddegrees = a1 + a2 m_drads = a1 - a2 End Function 

Luego, en el module estándar, obtienes tu comportamiento deseado así:

 Public Function getAngle(a As Double, b As Double) As clsTrig Dim oTrig As New clsTrig Call oTrig.doCalc(a, b) Set getAngle = oTrig End Function Sub test() MsgBox getAngle(30, 20).degrees MsgBox getAngle(30, 20).rads End Sub 

Usando un tipo:

 Option Explicit Type cType Degrees As Double rads As Double End Type Sub tester() Dim a As cType a = getAngle(1, 2, 3) Debug.Print a.Degrees, a.rads End Sub Public Function getAngle(a As Double, b As Double, c As Double) As cType Dim rv As cType rv.Degrees = 88 'for example rv.rads = 99 'for example getAngle = rv End Function