moveToElementText Method

Moves the specified IHTMLTxtRange object to the HTML element specified in the element argument.

expression.moveToElementText(element)

*expression   * Required. An expression that returns an IHTMLTxtRange object.

element    Required IHTMLElement object. The HTML element to which to move the specified IHTMLTxtRange object.

Example

The following example inserts two paragraphs into the active document, and then moves the IHTMLTxtRange object to modify the contents of each paragraph.

Sub MoveToBookmarkMethod()
    Dim objRange As IHTMLTxtRange
    Dim strBookmark As String
    
    ActiveDocument.body.innerHTML = "<p>Line One</p><p>Line two</p>"

    Set objRange = ActiveDocument.body.createTextRange
    
    objRange.moveToElementText ActiveDocument.body.all.tags("p").Item(0)
    strBookmark = objRange.getBookmark
    
    With objRange
        .moveToElementText ActiveDocument.body.all.tags("p").Item(1)
        .Text = "Changed Line 2"
        .moveToBookmark strBookmark
        .Text = "Changed Line 1"
        .Select
    End With
End Sub

Applies to | IHTMLTxtRange Object