You are here:

Excel/Set reference to add-in VBA

Advertisement


Question
QUESTION: Pearson Software Consulting wrote: 6-October-2007  

To load or unload an Add-In using VBA code, use
       Application.AddIns("AddIn Displayed Name").Installed = True

http://www.fontstuff.com/vba/vbatut08.htm
VBA Tips: How to Use Your Excel Add-In Functions in VBA
further wrote

The first thing to do is give your Add-In a unique VBA Project Name.

I made an addin with filename t.xlam
VBA project name "ct"

I can see them in Add in dialog boxes.
I can make it work manually tick them but not through code.

I tried
Application.addins("t").installed=true

Application.addins("ct").installed=true

a = Application.AddIns.Count
For i = 1 To a
Debug.Print AddIns(i).Name
If AddIns(i).Name = "t.xlam" Then Application.AddIns(i).Installed = True
Next

All failed.

Can you advise what I must do please?

Regards
KC

ANSWER: Hi Cheung,

Perhaps this article helps:

http://www.jkp-ads.com/Articles/DistributeMacro10.asp

---------- FOLLOW-UP ----------

QUESTION: Thank you for your advice.

I read from your article the addin MUST be in the default library location. I can manually add it in, but programmatically I got err 75. I am investigating.

Regards
KC

Answer
No, not necessarily. An add-in can be in ANY folder.

I use code like this to let an add-in install itself:

In a normal module:

Public Sub CheckInstall()
   Dim oAddIn As AddIn
   If Not IsInstalled Then
       If MsgBox("Do you wish to install '" & ThisWorkbook.Name & "' as an addin?", vbQuestion + vbYesNo, "Install Add-in?") = vbYes Then
         'This adds the add-in to the list of add-ins:
         Set oAddIn = Application.AddIns.Add(ThisWorkbook.FullName, False)
         'This checks the add-in in that list (and hence "installs" it):
         oAddIn.Installed = True
       End If
   End If
End Sub

Public Function IsInstalled() As Boolean
   Dim oAddIn As AddIn
   If ThisWorkbook.IsAddin Then
       For Each oAddIn In Application.AddIns
         If LCase(oAddIn.FullName) = LCase(ThisWorkbook.FullName) Then
         If oAddIn.Installed Then
         IsInstalled = True
         Exit Function
         End If
         End If
       Next
   Else
       IsInstalled = True
   End If
End Function

In ThisWorkbook:

Private Sub Workbook_Open()
   CheckInstall
ENd Sub
About Excel
This topic answers questions related to Microsoft Excel spreadsheet (or workbook) stand-alone or Mircrosoft Office Excel including Excel 2003, Excel 2007, Office 2000, and Office XP. You can get Excel help on Excel formulas(or functions), Excell macros, charting in Excel, advanced features, and the general use of Excel. This does not provide a general Excel tutorial nor the basics of using a spreadsheet. It provides specific answers to using Microsoft Excel only. If you do not see your Excel question answered in this area then please ask an Excel question here

Excel

All Answers


Answers by Expert:


Ask Experts

Volunteer


Jan Karel Pieterse

Expertise

Excel and Excel/VBA questions

Experience

Excel MVP

Organizations
Self employed Excel developer

Education/Credentials
Bachelor in Chemical Engineering

Awards and Honors
Microsoft MVP award since 2002

Past/Present Clients
Shell, Fortis bank, ABN-AMRO bank, Morgan Stanley, ...

©2016 About.com. All rights reserved.