# How to load an Excel add in and use a User Defined Type from that add in?

Type Quantity
i As Integer
end type

Sub show_quant(q as Quantiy)
MsgBox(q.i)
end sub


In another workbook, I do:

Sub load_addin()
AI.Installed = True

Dim q As Quantity
show_quant(q)
End Sub


This doesn't work. Excel complains that the User defined type hasn't been defined yet.

So how do you declare variables of a type defined in an add in?

-

The only way I've ever been able to get something like that to work is to follow the instructions on this page: http://fontstuff.com/vba/vbatut08.htm Specifically, you have to give the vba project name a new name, and you need to add it as a reference, using that name. The website explains it better.

Another page discussing the same thing: calling-add-in-functions-from-vba

-

This worked for me without manually adding the reference:

Private Sub Workbook_Open()
Dim success As Boolean

' Load and install new XLAM

End If
Next

Sub AddReference(AddInPath As String)