3

我有一个连接到 Excel 并加载工作簿的 VB6/VBA 应用程序。多年来,它一直运行良好。我们现在已经升级到 Excel 2010 并且遇到了一些问题。故障排除后,如果我关闭 PowerPivot COM 加载项,该进程似乎可以像以前一样运行,没有任何问题。当我寻找这个的确切原因时,我想看看我是否可以只为我的应用程序关闭该加载项。我像这样加载Excel:

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

在测试 Excel 工作簿上,我有此代码来列出加载项。然而,只有“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

在找到引用 COM 加载项的方法后,我需要阻止它加载到我的应用程序的 Excel 对象中。欢迎任何帮助或建议。

谢谢

4

2 回答 2

1

我不知道是否有一种“漂亮”的方式来实现这一点,但一种“肮脏”的方式是在启动 Excel 之前更改加载项的注册表设置,这样它就不会被加载。这可以通过将 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 插件。

于 2011-10-28T13:31:52.357 回答
0

I have the same problem but there's an easier solution. I Just turn the Powerpivot add-in off from the excel(untick it) and turn it on again...problem fixed.

于 2012-09-06T01:27:58.997 回答