Click to install Addin

Posted on Thursday 2 March 2006

The following code will install an addin to the users local addins folder. There are two constants that need to be changed, well only one really if your installing a .xla. You will also need to modify the call to "Addcustommenu" which appears twice - make a call to your menu/entry points code.

The code actually saves a copy of it’s self into the users adding folder, this make it good for deployment over a network.

I use this code in conjunction with some modified code from JKP apps set up utility.

Const gsAppName As String = "Your Addin Name"
Const gsFilename As String = gsAppName & ".xla"

'---------------------------------------------------------------------------------------
' Procedure : auto_open
' DateTime : 02/03/2006 11:17
' Author : rmclean
' Purpose : Installs Addin to local addins folder
' Version : v1
'---------------------------------------------------------------------------------------
'
Sub auto_open()
On Error GoTo ErrorHander

''exit if in degub mode
If Dir(ThisWorkbook.Path & "\debug.ini") <> "" Then
Exit Sub
End If

If UCase(ThisWorkbook.FullName) = _
UCase(Application.LibraryPath & "\" & gsFilename) Then
On Error Resume Next
AddIns.Add (Application.LibraryPath & "\" & gsFilename)
AddIns(gsAppName).Installed = True
On Error GoTo ErrorHander

Call Addcustommenu ''CHANGE AS NEEDED

Exit Sub
Else
'opens a workbook in case
Workbooks.Add
'closes any workbook with the same name
On Error Resume Next
Workbooks(gsFilename).Close False
On Error GoTo ErrorHander

ThisWorkbook.SaveAs Filename:=Application.LibraryPath & "\" & gsFilename _
, FileFormat:=xlAddIn
AddIns.Add (Application.LibraryPath & "\" & gsFilename)
AddIns(gsAppName).Installed = True
End If

Call Addcustommenu ''CHANGE AS NEEDED

Exit Sub

ErrorHander:
MsgBox "An error 'appen, when i wrote this code I didn't thing this would happen. The error was: " _
& vbNewLine & vbNewLine _
& Err.Description & vbNewLine & vbNewLine _
& "Can you tell Ross Mclean about this. thanks", Title:=gsAppName, Buttons:=vbOKOnly

End Sub


2 Comments for 'Click to install Addin'

  1.  
    bius
    5 October 2006 | 6:49 pm
     

    where can I put the code? In which event of my .xla?

    Private Sub Workbook_Open() ?

    Private Sub Workbook_Activate()

    Private Sub Workbook_AddinInstall()
    I'm searching code for "a double-click self installing .xla file"
    thanks a lot.

  2.  
    14 October 2006 | 1:38 pm
     

    Just stick it in a stanard modual, it will run automatically when the workbook is open,

    You may have to change a few bits of the code

Leave a comment

(required)

(required)


.

Use [VBA] Your Code [/VBA], when posting code, cheers Ross x /


RSS feed for comments on this post | TrackBack URI