使用VB6进行Excel自动化时,我有这段代码已经使用了五年多。它基本上遍历插件,如果检测到特定的插件,则向用户发出消息。
Public xlapp As Excel.Application
Set xlapp = GetObject(, "Excel.Application")
Dim CurrAddin As Office.COMAddIn
For Each CurrAddin In xlApp.COMAddIns
2 LogMe "==>COM Add-In: " & CurrAddin.Description
'detect the PowerPivot add-in
3 If CurrAddin.Description = "PowerPivot for Excel" And CurrAddin.progID = "Microsoft.AnalysisServices.Modeler.FieldList" Then
4 LogMe "==>COM Add-In 'PowerPivot for Excel is set to load=" & CurrAddin.Connect
5 If CurrAddin.Connect = True Then
6 MsgBox "The PowerPivot Add-in for Excel is installed and set to load.", vbExclamation
End If
End If
9 Next CurrAddin
Error in MyAddInEnumerator
1004
Method '~' of object '~' failed
Line: 2
在这个程序例程上安装了错误捕捉器后,调试显示它发生在第二行。交互式调试显示实际上是在上一行中。CurrAddin似乎已经被初始化,因此问题出现在xlApp.COMAddIns处。
我有一个应用程序在许多具有相同版本的32位Excel 2010的机器上运行。这些机器运行Win7x86和Win7x64,除了一个之外,所有机器都没有错误。我只是想不通为什么这台机器会在使用“COMAddIns”对象时出错。