Take a look at my code...
I have created windows application.
I have placed on the form:
1) 1x textbox - Name: TxtExcelAddin
2) 2x buttons: - a) CmdBrowse (browse for addin)
b) CmdInstall (install addin)
Public Class Form1
Private Sub CmdBrowse_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CmdBrowse.Click
Dim dlgOF As OpenFileDialog = Nothing
Dim dRes As DialogResult = Windows.Forms.DialogResult.No
Try
dlgOF = New OpenFileDialog()
With dlgOF
.Filter = "Excel 2003 Addin file (*.xla)|*.xla|Excel 2007 Addin file (*.xll)|*.xll"
.FilterIndex = 0
.Multiselect = False
dRes = .ShowDialog()
If dRes = Windows.Forms.DialogResult.OK Then Me.TxtExcelAddin.Text = .FileName
End With
Me.CmdInstall.Enabled = (Me.TxtExcelAddin.Text.Length > 0)
Catch ex As Exception
MsgBox(ex.Message, MsgBoxStyle.Exclamation, "Error no. " & Err.Number)
Finally
dlgOF = Nothing
dRes = Nothing
End Try
End Sub
Private Sub CmdInstall_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CmdInstall.Click
Dim oExc As Object = Nothing, oAds As Object = Nothing, oAin As Object = Nothing
Dim sFileName As String = String.Empty
Try
sFileName = Me.TxtExcelAddin.Text
oExc = CreateObject("Excel.Application")
oExc.Workbooks.Add()
oAds = oExc.AddIns
oAin = oAds.Add(sFileName, True)
oAin.Installed = True
MsgBox("Excel Addin installed: " & oAin.Installed, MsgBoxStyle.Information, "Information...")
Catch ex As ArgumentException
MsgBox(ex.Message, MsgBoxStyle.Exclamation, "Error no. " & Err.Number)
Catch ex As Exception
MsgBox(ex.Message, MsgBoxStyle.Exclamation, "Error no. " & Err.Number)
Finally
oExc.Quit()
oAin = Nothing
oAds = Nothing
oExc = Nothing
End Try
End Sub
End Class
I'm not using Interop and installer class. The code is executing without errors.
I hope it will be helpful for you.