Is there a way to remove an addin from the list of available addins in Excel?
I run into a problem because i have two addins required for my 'workflow'. I have a COM addin with some functions and a ribbon in Excel. Besides that i have an addin in the xll format based on the ExcelDna package for my user-defined functions (because ExcelDna provides intellisense for UDF). My worksheets require the UDF's from the xll-addin. I have written a subroutine that checks if the latest version of the xll-addin is installed, if not it replaces it for the newest version. The code i have written works when i test it. But when i close and reopen Excel it runs into an exception on this line dnaAddin = addIns.Add(GetDnaAddinDestinationPath). It seems like Excel renames the xll-addin when closing (see attached image).The selected addin is the renamed one. The activated one is the addin's real name.
I want to remove the renamed addin from the list because that seems to be a problem.
Check the subroutine below:
Public Shared Sub ActivateDnaAddin()
Dim sourcePath As String = GetDnaAddinSourcePath()
Dim destPath As String = GetDnaAddinDestinationPath()
Dim filePath As String = ""
Dim dnaAddin As AddIn = Nothing
If IsExcel64Bit() Then
Dim addIns As AddIns = Globals.ThisAddIn.Application.AddIns
For Each addIn As AddIn In addIns
If addIn.Name = DNA_ADDIN_FRIENDLYNAME Then
'this is where i want to remove the addin.
addIn.Installed = False
End If
If addIn.Name = GetDnaAddinFileName() Then
filePath = addIn.FullName
dnaAddin = addIn
End If
Next
Else
Dim addIns As AddIns2 = CType(Globals.ThisAddIn.Application.AddIns, AddIns2)
For Each addIn As AddIn In addIns
If addIn.Name = DNA_ADDIN_FRIENDLYNAME Then
addIn.Installed = False
End If
If addIn.Name = GetDnaAddinFileName() Then
filePath = addIn.FullName
dnaAddin = addIn
End If
Next
End If
If dnaAddin Is Nothing Then
GoTo InstallAddin
Else
GoTo RefreshAddin
End If
InstallAddin:
File.Copy(sourcePath, destPath, True)
If IsExcel64Bit() Then
Dim addIns As AddIns = Globals.ThisAddIn.Application.AddIns
dnaAddin = addIns.Add(GetDnaAddinDestinationPath)
Else
Dim addIns As AddIns2 = CType(Globals.ThisAddIn.Application.AddIns, AddIns2)
dnaAddin = addIns.Add(GetDnaAddinDestinationPath)
End If
dnaAddin.Installed = True
Exit Sub
RefreshAddin:
Dim dateInstalled As DateTime = GetFileCreationDate(filePath)
Dim dateBase As DateTime = GetFileCreationDate(sourcePath)
If dateBase.Equals(dateInstalled) Then
If Not dnaAddin.Installed Then
dnaAddin.Installed = True
End If
Else
If dnaAddin.Installed Then
dnaAddin.Installed = False
End If
GoTo InstallAddin
End If
Exit Sub
End Sub