Scripts.Item(Object) Method

Definition

Returns a member of the Scripts collection.

public:
 Microsoft::Office::Core::Script ^ Item(System::Object ^ Index);
public Microsoft.Office.Core.Script Item (object Index);
abstract member Item : obj -> Microsoft.Office.Core.Script
Public Function Item (Index As Object) As Script

Parameters

Index
Object

Required Object. The ID or index number of the script to be returned.

Returns

Remarks

Accepts the index number or ID of the script you want the Microsoft Office application to return. The Item method accepts an Object value that can accept either an ordinal number (index value), which returns the script stored at that position in the Scripts collection, or a String value that represents the name or ID of the script.

The Scripts collection contains all of the scripts in a given document, in source order (the order in which Script objects appear in the source file). Scripts are maintained in source order regardless of their location in the document — that is, whether they’re in the header or the body text.

You can use the Item method to access a script in the Scripts collection by using the ID of the <SCRIPT> tag. The ID attribute of the <SCRIPT> tag is identical to the Id property of the Script object. If there are duplicate or multiple IDs in the document and you use the Id property of a Script object to access a script by using the Item method, Office returns the first script that matches the ID; additional scripts with the same ID are ignored.

New script anchors added to the collection are appended to the end of the Scripts collection in the order in which they were added to the document. The script anchors remain in this order until the document is saved as HTML, closed, and then opened again in the host application. Following these steps causes the Scripts collection to be indexed in the order in which the script anchors appear in the document, which may be different than the order in which they were added to it. Therefore, you’re advised to use the Id property of the Script object, rather than the script’s position in the collection, to ensure positive identification of the script.

Applies to