Remove Method
Applies To
Collection object.
Description
Removes a member from a Collection object.
Syntax
object.Remove index
The Remove method syntax has the following object qualifier and part
Part | Description |
|
object | Required. An object expression that evaluates to an object in the Applies To list. |
index | Required. An expression that specifies the position of a member of the collection. If a numeric expression, index must be a number from 1 to the value of the collection's Count property. If a string expression, index must correspond to the key argument specified when the member referred to was added to the collection. |
Remarks
If the value provided as index doesn't match an existing member of the collection, an error occurs.
See Also
Add method, Add method ("Extensibility Object Model Language Reference"), Item method, Item method ("Extensibility Object Model Language Reference"), ItemAdded event ("Extensibility Object Model Language Reference"), ItemRemoved event ("Extensibility Object Model Language Reference").
Example
This example illustrates the use of the Remove method to remove objects from a Collection object, MyClasses. This code removes the object whose index is 1 on each iteration of the loop.
Dim Num, MyClasses
For Num = 1 To MyClasses.Count
MyClasses.Remove 1 ' Remove the first object each time
' through the loop until there are
' no objects left in the collection.
Next Num
Example (Extensibility Object Model)
The example verifies that a particular member of the VBComponents collection is a module, and then it uses the Remove method to remove the module.
Debug.Print Application.VBE.ActiveVBProject.VBComponents(4).Name
Application.VBE.ActiveVBProject.VBComponents.Remove _
Application.VBE.ActiveVBProject.VBComponents(4)