Save & Install Add-In with VBA

M

Matt

I'm trying to write code to save an activeworkbook as an
addin and then install the addin just saved. Can anyone
help me with this?
 
D

Dave Peterson

This seemed to work ok for me:

Option Explicit
Sub testme()

Dim wkbk As Workbook
Dim myAddin As AddIn
Dim myPath As String
Dim myFileName As String

myPath = "C:\my documents\excel\"
myFileName = "book1.xla"

Set wkbk = ActiveWorkbook

If wkbk Is ThisWorkbook Then
MsgBox "not this workbook!"
Exit Sub
End If

With wkbk
.IsAddin = True
Application.DisplayAlerts = False
.SaveAs Filename:=myPath & myFileName, FileFormat:=xlAddIn
Application.DisplayAlerts = True
.Close savechanges:=False
End With

On Error Resume Next
Application.AddIn(myFileName).Installed = False
On Error GoTo 0

Set myAddin = AddIns.Add(Filename:=myPath & myFileName)
myAddin.Installed = True

End Sub
 
Top