How can I move the cursor to a postion where I want in office word by vb?

我怕爱的太早我们不能终老 提交于 2019-12-12 01:12:56

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!