问题
12345qwesdfasdf22232 & 021930
Like the string above, I want to move the cursor to the position after the character &
by searching the character in the string. How can I achieve it when I using visual basic to control the word?
Option Explicit
Dim WordApp As Word.Application
Private Sub Command2_Click()
Set WordApp = New Word.Application
WordApp.Documents.Open CommonDialog1.FileName
WordApp.Visible = True
WordApp.DisplayAlerts = False
...
End Sub
回答1:
If you are outputting using Selection.TypeText
, you can use
Selection.MoveStartUntil "&", wdBackward
Selection.MoveLeft 1
which will move you backwards until the first occurrence of the ampersand.
You can also do as Cindy Meister mentioned, do a Selection.Find
similar to...
With Selection.Find
.MatchWildCards = false
.Text = "&"
.Execute
End With
来源:https://stackoverflow.com/questions/36737670/how-can-i-move-the-cursor-to-a-postion-where-i-want-in-office-word-by-vb