我有一个VB6 / VBA应用程序挂钩到Excel并加载工作簿。多年来它一直很好用。我们现在已升级到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对象中加载它。欢迎任何帮助或建议。
由于
答案 0 :(得分: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插件。
答案 1 :(得分:0)
我有同样的问题,但有一个更简单的解决方案。 我只需从excel关闭Powerpivot加载项(取消它)并再次打开它...问题已解决。