Returns an IHTMLElementCollection collection that represents the collection of all elements in the document.
expression.all
expression Required. An expression that returns a DispFPHTMLDocument object.
The collection includes one element object for each valid HTML tag. If a valid tag has a matching end tag, both tags are represented by the same element object.
The collection always includes the HTML, HEAD, TITLE and BODY objects regardless of whether the tags are present in the document.
If the document contains invalid or unknown tags, the collection includes one element object for each tag. Therefore, invalid or unknown end or beginning tags are represented by their own element objects in the collection. The order of the element objects is the HTML source order. Although the collection indicates the order of tags, it does not indicate hierarchy.
The following example displays the tag name of each element in the current document. The Length property is used to return the index position of the last element in the collection. Because the collection is zero-based (the first element in the collection has the index value zero (0)), use Length - 1
to return the number of elements in the collection.
Sub ElementCollection()
'Returns the collection of all elements in the active document
Dim objAll As IHTMLElementCollection
Set objAll = FrontPage.ActiveDocument.all
For i = 0 To objAll.Length - 1
'Display names of all element items in collection
MsgBox "Element tag name: " & objAll.Item(i).tagName
Next i
End Sub