Load Add-in's Without Using Add-in Manager

M

McRolin

Hello All,
I have built an Excel add-in (C++) containing a set of lognormal
distribution functions. I want to distribute the add-in but currently
require the user to open Excel and load the add-in using the add-in manager.
I would prefer to "add" the add-in to Excel's add-in list during my
installation. Is there away to automatically load the add-in without having
the user manually do it?

Thanks, Roger
 
R

Robin Hammond

Roger,

try this.

Sub InstallAddIn()
'this is a VB routine that runs as part of an external installation package
to register an add-in with xl
'this was based on something I saw in the groups I think, but apoligies to
original author since I cannot remember who it was

Dim strApp As String
Dim strAddInPath As String
Dim oAddin As Object
Dim oXL As Object
Dim nExcelCount As Integer

strApp = App.Path

nExcelCount = 0

TestForExcel:

On Error Resume Next
Set oXL = GetObject(, "Excel.Application")
On Error GoTo 0

If Not (oXL Is Nothing) Then

If nExcelCount = 0 Then

Call MsgBox("Please save any files and quit Microsoft Excel then
press OK", _
vbOKOnly, msgTitle)

Else

Call MsgBox("You still have Excel running. To register this add-in
with Excel " & _
"you need to exit Excel first" & vbCrLf & vbCrLf & _
"If you can't see a running instance of Excel you may have a
hidden instance running" & vbCrLf & vbCrLf & _
"To close a hidden instance, press ALT-CTRL-DEL and remove Excel
from the list of running processes", _
vbOKOnly + vbInformation, msgTitle)

End If

nExcelCount = nExcelCount + 1
Set oXL = Nothing
GoTo TestForExcel

End If

Set oXL = CreateObject("Excel.Application")

'have to add a workbook or you can't add an add-in
oXL.Workbooks.Add

'never been happy with this line since the user could have changed the
default install path
'if you are running your own installer, you could make sure you trap the
right path
strAddInPath = Environ("ProgramFiles") & "\Enhanced
Datasystems\EFALoader.xla"

Set oAddin = oXL.Addins.Add(strAddInPath)
oAddin.installed = True
oXL.Quit
Set oXL = Nothing

Call MsgBox("Install complete", vbInformation + vbOKOnly, "Enhanced
Datasystems")

End Sub

Robin Hammond
www.enhanceddatasystems.com
 
S

Stephen Bullen

Hi Roger,
I have built an Excel add-in (C++) containing a set of lognormal
distribution functions. I want to distribute the add-in but currently
require the user to open Excel and load the add-in using the add-in manager.
I would prefer to "add" the add-in to Excel's add-in list during my
installation. Is there away to automatically load the add-in without having
the user manually do it?

Sure. Find the registry key:

HKEY_CURRENT_USER\Software\Microsoft\Office\9.0\Excel\Options

where 9.0 is Excel 2000, 10.0 is Excel XP etc.

In there, add a new string value, with the next item in the sequence:

OPEN
OPEN1
OPEN2
... etc

i.e. if OPEN doesn't exist, use that. If OPEN, OPEN1 and OPEN2 exist, you
have to use OPEN3. The value of the key is the file name of your xll.

Regards

Stephen Bullen
Microsoft MVP - Excel
www.BMSLtd.ie
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top