Sebastian Kirsche
Sebastian Kirsche

Reputation: 883

Unable to access Excel's Application.ComAddIns property if there are no AddIns installed

This code snipped for the Windows Scripting Host displays the number of COM-AddIns currently installed into Excel.

It works fine except for when there are no COM-AddIns installed. I believe it should output a "0", but instead it raises an exception (code 800A03EC). Does anyone know why?

test.vbs

Set objExcel = CreateObject("Excel.Application")
WScript.Echo objExcel.ComAddIns.Count

Upvotes: 2

Views: 1126

Answers (1)

Tmdean
Tmdean

Reputation: 9309

Looks like a bug in Excel. You'll probably have to abuse VB's error handling to work around it.

On Error Resume Next
WScript.Echo objExcel.ComAddIns.Count
If Err And Err.Number = 1004 Then
    WScript.Echo "No add-ins"
End If
On Error GoTo 0

Upvotes: 3

Related Questions