Collection.Add Method |
Named Arguments
Yes
Syntax
objectvariable.Add item [, key, before, after]
objectvariable
Use: Required
Data Type: Collection object
The name of the Collection object to which an item is to be added.
item
Use: Required
Data Type: Any
An expression of any type that specifies the member to add to the collection.
key
Use: Optional
Data Type: String
A unique string expression that specifies a key string that can be used instead of a positional index to access a member of the collection.
before
Use: Optional
Data Type: String or Numeric
An expression that specifies a relative position in the collection. The member to be added is placed in the collection before the member identified by the before argument.
after
Key: Optional
Data Type: String or Numeric
An expression that specifies a relative position in the collection. The member to be added is placed in the collection after the member identified by the after argument.
Description
Adds a data item to a collection.
Rules at a Glance
If you don't specify a before or after value, the member is appended to the end of the collection.
If you don't specify a key value, you can't then access this member using a key, but instead must access it either by using its ordinal number or by enumerating all the members of the collection with the For Each...Next construct.
Whether the before or after argument is a string expression or a numeric expression, it must refer to an existing member of the collection, or an error (runtime ...
Get VB & VBA in a Nutshell: The Language now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.