VB6/VBA不允许加载COM加载项 [英] VB6/VBA Do not Allow COM Add-In to load
问题描述
我有一个VB6/VBA应用程序,可以挂接到Excel并加载工作簿.多年来一直运行良好.我们现在已升级到Excel 2010,并遇到了一些问题.故障排除后,如果我关闭PowerPivot COM加载项,则该进程可以像以前一样运行,没有任何问题.当我寻找导致此问题的确切原因时,我想看看是否可以仅针对我的应用程序关闭该加载项.我这样加载Excel:
I have a VB6/VBA application that hooks into Excel and loads a workbook. It has been working great for many years. We have now upgraded to Excel 2010 and have ran into some issues. After troubleshooting it seems that if i turn off the PowerPivot COM Add-In the process is able to run as it did before with no issues. While I look for the exact cause of this i wanted to see if i can turn off that Add-In just for my app. I load up Excel like this:
Set xlApp = CreateObject("Excel.Application")
xlApp.Visible = False
在一个测试Excel工作簿上,我有这段代码来列出加载项.但是,只有"Excel加载项"才被列出. "COM加载项"未列出.
On a test Excel workbook I have this code to list the add-ins. However only "Excel Add-Ins" are the only ones that get listed. "COM Add-Ins" do not get listed.
Sub ListAddIns()
Dim CurrAddin As Excel.AddIn
Dim r As Long
Dim ws As Excel.Worksheet
Set ws = ActiveSheet
Cells.Select
Selection.ClearContents
Range("A1").Select
r = 1
For Each CurrAddin In Excel.Application.AddIns
ws.Cells(r, 1).Value = CurrAddin.FullName
ws.Cells(r, 2).Value = CurrAddin.Installed
ws.Cells(r, 3).Value = CurrAddin.Name
ws.Cells(r, 4).Value = CurrAddin.Path
ws.Cells(r, 5).Value = CurrAddin.progID
ws.Cells(r, 6).Value = CurrAddin.CLSID
r = r + 1
Next CurrAddin
MsgBox "Its done.", vbInformation
End Sub
找到一种引用COM加载项的方法后,我需要阻止它加载到我应用程序的Excel对象中.欢迎任何帮助或建议.
After I find a way to reference the COM Add-In I need to keep it from loading in the Excel object in my app. Any help or suggestions welcome.
谢谢
推荐答案
我不知道是否有漂亮"的方法来实现此目的,但肮脏"的方法是更改添加的注册表设置-在启动Excel之前-不会加载它.
可以通过将HKCU \ Software \ Microsoft \ Office \ Excel \ AddIns \\ LoadBehavior设置为0(不会自动加载)来完成.
但是,除非您确定用户接受此操作,否则可能不应该这样做,因此请务必询问用户是否同意此更改.
I don't know if there is a "pretty" way to achieve this, but a "dirty" way would be to change the registry settings for the add-in before you start Excel so it won't be loaded.
This can be done by setting HKCU\Software\Microsoft\Office\Excel\AddIns\\LoadBehavior to 0 (don't load automatically).
However, this is something you probably shouldn't do unless you are sure that the user accepts it, so be sure to ask the user if he agrees to this change.
您与代码非常接近,方法如下:
You were very close with your code, the way to go is something like this:
Sub ListAddIns()
Dim CurrAddin As **Office.COMAddIn**
Dim r As Long
Dim ws As Excel.Worksheet
Set ws = ActiveSheet
Cells.Select
Selection.ClearContents
Range("A1").Select
r = 1
For Each CurrAddin In **Excel.Application.COMAddIns**
ws.Cells(r, 1).Value = CurrAddin.Description
ws.Cells(r, 2).Value = CurrAddin.Application
ws.Cells(r, 3).Value = CurrAddin.GUID
ws.Cells(r, 4).Value = CurrAddin.Connect
ws.Cells(r, 5).Value = CurrAddin.Creator
ws.Cells(r, 6).Value = CurrAddin.progID
r = r + 1
Next CurrAddin
MsgBox "Its done.", vbInformation
End Sub
您可以使用Connect属性来加载和卸载COM加载项.
You can use the Connect property to load and unload a COM addin.
这篇关于VB6/VBA不允许加载COM加载项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!