提问人:Redbad 提问时间:7/16/2023 更新时间:7/16/2023 访问量:39
从可用加载项列表中删除 Excel 加载项
Remove Excel AddIn from the list of available addins
问:
有没有办法从Excel中的可用加载项列表中删除加载项?
我遇到了一个问题,因为我的“工作流”需要两个插件。我有一个COM插件,其中包含一些功能和Excel中的功能区。除此之外,我还有一个基于 ExcelDna 包的 xll 格式的插件,用于我的用户定义函数(因为 ExcelDna 为 UDF 提供了智能感知)。我的工作表需要来自 xll-addin 的 UDF。我编写了一个子例程来检查是否安装了最新版本的 xll-addin,如果没有,它会将其替换为最新版本。我编写的代码在测试时有效。但是当我关闭并重新打开 Excel 时,它在此行上遇到了异常。似乎 Excel 在关闭时重命名了 xll-addin(见附图)。所选插件是重命名的插件。激活的那个是插件的真实姓名。我想从列表中删除重命名的加载项,因为这似乎是一个问题。dnaAddin = addIns.Add(GetDnaAddinDestinationPath)
检查下面的子例程:
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
答: 暂无答案
评论