Requested member of the collection does not exist

See Also

The "requested member of the collection does not exist" error occurs when you try to access an object that doesn't exist. For example, the following instruction may post an error if the active document doesn't contain at least one table.

ActiveDocument.Tables(1).Select

To avoid this error when accessing a member of a collection, ensure that the member exists prior to accessing the collection member. If you're accessing the member by index number, you can use the Count property to determine if the member exists. The following example selects the first table if there is at least one table in the active document.

If ActiveDocument.Tables.Count >=1 Then
    ActiveDocument.Tables(1).Select
Else
    MsgBox "Document doesn't contain a table"
End If

If you're accessing a collection member by name, you can loop on the elements in a collection using a For Each...Next loop to determine if the named member is part of the collection. For example, the following example deletes the AutoCorrect entry named "acheive" if it's part of the AutoCorrectEntries collection.

For Each aEntry In AutoCorrect.Entries
    If aEntry.Name = "acheive" Then aEntry.Delete
Next aEntry