DISP_E_BADINDEX (0X8002000B) — Invalid index fix
This COM error means you're trying to access an array or collection with an index that doesn't exist. The culprit is almost always a hardcoded array index in VBA or PowerShell that's out of bounds.
What is DISP_E_BADINDEX?
You'll see this error when your script tries to access an element in a COM collection or array using an index that doesn't exist. The index might be 0-based when you thought it was 1-based, or the collection is empty, or you're referencing a property that doesn't exist. The exact HRESULT is 0x8002000B, and it's been around since Windows 95. I've seen it more times than I can count in VBA macros, PowerShell automation, and even ancient ASP pages.
Cause #1: Hardcoded Array Index in VBA
This is the most common cause. You write something like Sheets(1) or Workbooks(2) in Excel VBA, or Items(3) in Outlook, and the collection doesn't have that many items. The index is off by one because VBA collections are 1-based, but some COM objects use 0-based indexing. I've seen people assume Sheets(0) works — it doesn't. VBA collections start at 1.
Fix: Always check the count first
Before accessing any item by index, verify the collection size. Use If Collection.Count >= N Then to guard your access. Here's a solid pattern for Excel:
Dim ws As Worksheet
If ThisWorkbook.Sheets.Count >= 1 Then
Set ws = ThisWorkbook.Sheets(1)
Else
MsgBox "No sheets found"
Exit Sub
End If
For Outlook, same approach:
Dim olItems As Items
Set olItems = olFolder.Items
If olItems.Count >= 3 Then
Debug.Print olItems(3).Subject
Else
Debug.Print "Not enough items"
End If
Don't hardcode indexes. Use For Each loops instead — they avoid this error entirely and are easier to read.
Cause #2: Indexing into an Empty Collection or Array
This is the second most common scenario. You query WMI, get a collection back, and assume it has data. But if the query returns nothing — say no running processes match your criteria — you try to access objItem(0) and boom, 0x8002000B. PowerShell with COM objects does this too.
Fix: Check for Nothing and Count
Always test if the collection exists and has items. Here's a WMI example in VBScript that's saved my hide more than once:
Set colItems = GetObject("winmgmts:").ExecQuery _
("SELECT * FROM Win32_Process WHERE Name = 'notepad.exe'")
If Not colItems Is Nothing Then
If colItems.Count > 0 Then
For Each objItem In colItems
WScript.Echo objItem.Name
Next
Else
WScript.Echo "No matching processes found"
End If
End If
In PowerShell with COM:
$items = (New-Object -ComObject Scripting.FileSystemObject).GetFolder("C:\Windows").Files
if ($items.Count -gt 0) {
Write-Output $items.Item(0).Name
} else {
Write-Warning "Folder is empty"
}
Cause #3: Wrong Property Name or Method Call
Less common but still happens. The error fires when you try to access a property that doesn't exist on the object, but COM interprets it as a bad index. For example, trying to read obj.SomeProperty(0) when SomeProperty isn't a collection. Or passing an invalid parameter to a method that expects a specific index range.
Fix: Review the object's interface
Check the documentation or use IntelliSense in your IDE. If you're working with an unfamiliar COM object, dump its properties and methods:
' In VBA with early binding
Dim obj As SomeLibrary.SomeClass
' Use Object Browser (F2) to explore
' In PowerShell
$obj = New-Object -ComObject SomeProgID
$obj | Get-Member -MemberType Properties, Methods
I've seen this with Excel's Range object — people try Range("A1").Value(0) thinking it's an array. It's not. Value returns a variant, not a collection. Use Range("A1:A10").Value as a 2D array instead.
Quick-Reference Summary
| Cause | How to spot | Fix |
|---|---|---|
| Hardcoded index, off-by-one | Using literal numbers like Sheets(1) or Items(3) |
Check .Count first, use For Each loops |
| Empty collection | WMI or folder queries returning zero results | Test Count > 0 before accessing items |
| Wrong property/method signature | Trying to index a non-indexed property | Verify the object model with Get-Member or Object Browser |
That covers the three main reasons you see 0x8002000B. In 14 years, I've never seen it come from anything else — no hardware issue, no corrupt file, just bad indexing. Fix your index, fix the error. Move on.
Was this solution helpful?