IHTMLElement Object

Microsoft FrontPage Visual Basic

IHTMLElement Object

Multiple objects IHTMLElement
Multiple objects

Represents any HTML element in an HTML document.

While most HTML elements have a corresponding object, use the IHTMLElement object to access elements for which there isn't a corresponding object. For example, the HEAD element doesn't have a corresponding object in the Microsoft FrontPage Visual Basic for Applications (VBA) Page Object Model. In this case, to access the elements and properties related to the HEAD element, create an IHTMLElement object to access the HEAD element in a document.

Also use the IHTMLElement object to loop through objects in an IHTMLElementCollection collection that is made of of more than one type of element.

Using the IHTMLElement Object

Use the tags method to return an IHTMLElementCollection collection that represents a collection of a specific type of element in a document. Use the Item method to return an IHTMLElement object that accesses a specific element, referenced by ordinal number or by the value of the id attribute.

The following example accesses the HEAD element in the active document. While there is only one HEAD element in an HTML document, the tags method returns an IHTMLElementCollection collection, so the Item method accesses the first, which is also the only HEAD element in the document.

    Dim objElement As IHTMLElement

Set objElement = ActiveDocument.all.tags("head").Item(0)
  

The following example uses the IHTMLElement object to loop through all the elements in the body of the active document and assign an id attribute based on the name of the element and the ordinal position of the element in the document.

    Dim objElement As IHTMLElement
Dim intCount As Integer

For Each objElement In ActiveDocument.body.all
    intCount = intCount + 1
    objElement.Id = objElement.tagName & intCount
Next