Question : WORD VBA Automation positionnig the cursor.

Hello Experts,

I would like to know how to position the cursor next to a particular key word within the document and find the position of the cursor.

If anyone can share some example code, or refer me to a website. It would be much appreciated.
 

Answer : WORD VBA Automation positionnig the cursor.

You just need to use Find and if successful set the Selection to the found place. This snippet will put the text cursor after the found text.

1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
Sub FindWord()
    Dim rng As Range
    
    Set rng = ActiveDocument.Range
    With rng.Find
        .Text = "MyKeyWord"
        If .Execute Then
            rng.Collapse wdCollapseEnd
            rng.Select
        Else
            MsgBox "Not found"
        End If
    End With
 
End Sub
Random Solutions  
 
programming4us programming4us