Move Method (Page Object Model)
Collapses an IHTMLTxtRange to the start of the range, and then moves the insertion point from the starting point in the range by the specified number of units. Returns a Long that represents the number of units moved.
expression.Move(Unit, Count)
*expression * Required. An expression that returns an IHTMLTxtRange object.
Can be one of the following values
character | Moves one or more characters. |
word | Moves one or more words. A word is a collection of characters terminated by a space or some other white-space character, such as a tab. Punctuation is also included in the word count, so a period at the end of a sentence or a comma in the middle of a sentence would increase the word count by one. |
sentence | Moves one or more sentences. A sentence is a collection of words terminated by a punctuation character, such as a period. |
textedit | Moves to the start or end of the original range. |
Count Optional Long. Specifies the number of units to move. This number can be positive (moves the insertion point to the right of the starting point in the range) or negative (moves the insertion point to the left of the starting point in the range). The default is 1.
Example
The following example takes an IHTMLTxtRange object, a custom fpMoveUnit enumerated type (included in the code) that represents the string value of the Unit argument, and an Integer that represents the number of units to move, and then returns an IHTMLTxtRange object that represents the range after the Move method is called.
Note Place the following custom enumerated type in the General Declarations section of the code module.
Public Enum fpMoveUnit
fpMoveCharacter
fpMoveWord
fpMoveSentence
fpMoveTextEdit
End Enum
Function MoveTextRange(objRange As IHTMLTxtRange, eUnit As fpMoveUnit, _
intCount As Integer) As IHTMLTxtRange
Dim strMoveUnit As String
Select Case eUnit
Case fpMoveCharacter
strMoveUnit = "character"
Case fpMoveWord
strMoveUnit = "word"
Case fpMoveSentence
strMoveUnit = "sentence"
Case fpMoveTextEdit
strMoveUnit = "textedit"
End Select
If strMoveUnit = "textedit" Then
objRange.Move strMoveUnit
Else
objRange.Move strMoveUnit, intCount
End If
Set MoveTextRange = objRange
End Function
Use the following example to call the preceding function.
Sub CallMoveTextRange()
Dim objRange As IHTMLTxtRange
Set objRange = ActiveDocument.body.createTextRange
Set objRange = MoveTextRange(objRange, fpMoveWord, 3)
objRange.Text = "<b>Hello, World!</b> "
End Sub
Applies to | IHTMLTxtRange Object