VB6 / VBA不允许加载COM加载项

我有一个VB6 / VBA应用程序挂钩到Excel并加载工作簿。 它已经工作了很多年了。 我们现在升级到Excel 2010,并遇到了一些问题。 在排除故障后,似乎如果closuresPowerPivot COM加载项,则可以像以前一样运行该程序,而不会出现问题。 当我寻找这个的确切原因,我想看看我是否可以closures只是为我的应用程序的加载项。 我像这样加载Excel:

Set xlApp = CreateObject("Excel.Application") xlApp.Visible = False 

在testingExcel工作簿,我有这个代码来列出加载项。 但是只有“Excel加载项”是唯一被列出的。 “COM加载项”不列出。

 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 

在find引用COM加载项的方法之后,我需要避免在我的应用程序中加载Excel对象。 任何帮助或build议的欢迎。

谢谢

我不知道是否有一个“漂亮”的方式来实现这一点,但“肮脏”的方法是在启动Excel之前更改加载项的registry设置,因此不会被加载。 这可以通过将HKCU \ Software \ Microsoft \ Office \ Excel \ AddIns \ LoadBehavior设置为0来完成(不要自动加载)。
但是,除非您确定用户接受,否则您可能不应该这样做,因此请务必询问用户是否同意此更改。

你非常接近你的代码,走的路是这样的:

 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插件。

我有同样的问题,但有一个更简单的解决scheme。 我只是从Excel中closuresPowerpivot插件(取消它),并再次打开…问题修复。