Save & Install Add-In with VBA

  • Thread starter Thread starter Matt
  • Start date Start date
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?
 
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
 

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

Back
Top