0X8002000D

DISP_E_ARRAYISLOCKED (0X8002000D) — Memory is locked

DISP_E_ARRAYISLOCKED happens when code tries to change an array that's locked by another process. Fix: unlock the array or use a copy.

Yeah, that error is annoying. You're in the middle of a VBA macro or a COM call, and suddenly DISP_E_ARRAYISLOCKED pops up. Let's cut through the noise.

The Fix That Works 90% of the Time

The culprit is almost always a locked array. Here's the deal: COM locks arrays when it hands them to you. If you try to modify that array directly, you get 0X8002000D. The fix is to copy the array to an unlocked one before touching it.

' VBA example — copy the locked array to a local array
Dim sourceArray As Variant
Dim localArray As Variant
' Get array from COM (e.g., a recordset or a custom object)
Set obj = CreateObject("Some.COM.Object")
sourceArray = obj.GetArray()  ' This array may be locked
' Copy it — this unlocks it
localArray = sourceArray
' Now you can modify localArray
localArray(0) = "changed"

The copy creates a new array in your process memory. The original locked array stays untouched, and COM is happy. That's it.

If you're not in VBA but in C++ or C#, same idea. Use SafeArrayCopy or Marshal.Copy.

Why This Works

COM uses SafeArrays to pass data between processes. When a COM method returns an array, it locks that array's memory so no one else can mess with it while your code is using it. The lock prevents race conditions. But sometimes the lock doesn't release properly, or your code tries to write to the array without telling COM. That's when you see the error.

By copying the array, you're telling COM: "I'm done with your version, I'll work with my own." The lock becomes irrelevant because you're not touching the original memory block.

Less Common Variations

Sometimes the simple copy doesn't work because the array is locked for a different reason. Here's what I've seen in the field:

1. The Array Is Still Being Used by Another COM Object

If you have an object that holds a reference to the array, the lock stays until that object releases it. For example, in Excel, a Range.Value returns a 2D array. If you pass that array to a custom class, and the class stores it, the lock might persist. Solution: before calling the COM method, set all references to Nothing or null.

Set rng = Nothing  ' release the range reference

2. Array Passed By Reference to a COM Method

If you pass an array to a COM method by reference (ByRef in VBA), and the method tries to modify it internally, you can hit this error. The fix is to pass by value (ByVal). In VBA, that means making a copy first.

Sub CallCom(ByVal arr As Variant)  ' ByVal — creates a copy
    obj.SomeMethod arr
End Sub

3. Multi-Dimensional Arrays from ADO Recordsets

ADO recordsets often return arrays that are locked. The fix is the same — copy — but be aware that GetRows returns a 2D array where the first dimension is fields, second is rows. Copying that works, but it's easy to mess up the indexes. Just do the copy and then handle it normally.

Dim data As Variant
data = rs.GetRows()  ' locked array
Dim unlockedData As Variant
unlockedData = data  ' copy

What NOT to Bother With

You'll see advice online about changing your Office version, reinstalling COM components, or tweaking registry settings. Don't waste time with that. This error is about array handling, not system config.

Also, don't try to unlock the array manually using SafeArrayUnlock unless you're writing C++ and you know exactly what you're doing. In VBA, you can't call that directly. The copy approach is always safer.

Prevention: How to Avoid It in the Future

Here are three habits that stop this error before it starts:

  • Always copy arrays immediately after receiving them from COM. Make it a rule: if it comes from a COM object, it gets copied before you touch it.
  • Pass arrays by value (ByVal) to your own procedures. This forces a copy and avoids accidental writes to the original.
  • Release object references (set to Nothing) as soon as you're done with them. Especially in loops, this prevents locks from lingering.

One more thing: if you're doing this in Excel VBA and you're writing to a range, don't write element by element. That's slow and can trigger odd COM behavior. Instead, build your array, copy it, and assign it to the range in one shot.

' Slow and occasionally problematic
For i = 1 To 10
    Sheet1.Cells(i, 1).Value = myArray(i)
Next i

' Fast and safe
Dim copyArray As Variant
copyArray = myArray
Sheet1.Range("A1:A10").Value = copyArray

That's the whole story. Copy the array, move on with your life. If you're still stuck, double-check that you're not holding a reference to the array somewhere else — that's the usual edge case.

Related Errors in Windows Errors
0XC00D1B74 Fix NS_E_INVALIDCALL_WHILE_ARCHIVAL_RUNNING (0XC00D1B74) 0X000020E5 AD cache missing naming context – fix for error 0x20E5 0XC00D1063 Fix 0XC00D1063: Missing media codec on Windows 0XC00000B5 STATUS_IO_TIMEOUT 0XC00000B5: Real Fix for Stuck Drives

Was this solution helpful?

EP
Erropedia Team
Tech Support Editors
The Erropedia editorial team researches and documents real-world tech errors from across Windows, Linux, macOS, networking, databases, cloud platforms, and more. Every solution is reviewed for accuracy and updated as software and systems evolve.