View Single Post
  #6   Report Post  
Posted to microsoft.public.excel.programming
Jamie Collins Jamie Collins is offline
external usenet poster
 
Posts: 593
Default Excel startup macros - visibility of...

ghost Wolf wrote ...

Exactly how would you go about setting up a reference to MyAddIn?


My workbook has a reference (in the VBE: Tools, References) to my
add-in's VBA project (named vbaServer), and the following code
applies:

' ---<In class module named MyClass in add-in
' Set Instancing property to 2 - PublicNotCreatable
Option Explicit

Private Const SECRET_TEXT As String = "" & _
"Hippo"

Public Property Get Secret() As String
Secret = SECRET_TEXT
End Property
' ---</In class module named MyClass in add-in


' --- <In a standard module in add-in ---
Option Explicit

Public Function GetClassInstance() As MyClass
Dim oMyClass As MyClass
Set oMyClass = New MyClass
Set GetClassInstance = oMyClass
End Function
' --- </In a standard module in add-in ---


' ---<In ThisWorkbook code module of workbook
Option Explicit

Private Sub Workbook_Open()
Dim Instance1 As vbaServer.MyClass
Set Instance1 = vbaServer.GetClassInstance()
MsgBox Instance1.Secret
End Sub
' ---</In ThisWorkbook code module of workbook


Jamie.

--