0

谁能告诉,如何在word文档中找到一个特定的单词并使用vba代码将一个单词粘贴到该单词附近?

我已经打开了文档。所以我只想找到这个词并在它附近粘贴一个词。我已经使用 movedown 和 moveright 方法完成此操作以转到该特定单词。但它更依赖于光标的位置。

谢谢,

婆罗提

4

1 回答 1

0

我在访问中使用它,我不知道它是否适合你。

Dim mWord As Word.Application
Dim mDoc As Word.Document
Dim mRange As Word.Range

Set mDoc = mWord.Documents.Open("YourPath")
mDoc.SaveAs "Where you want to save"

Set mWord = New Word.Application
mWord.Visible = False

DoEvents
Set mRange = mWord.ActiveDocument.Content

mRange.Find.Execute FindText:=TextToFind1, ReplaceWith:=TextToFind1 & TextToReplace1, Replace:=wdReplaceAll
mRange.Find.Execute FindText:="TextToFind2", ReplaceWith:="TextToReplace2", Replace:=wdReplaceAll
Set mRange = Nothing

mDoc.Save

'Display
mWord.Visible = True

Shell "Explorer.exe /n,/e," & "DirectoryToOpen", vbNormalFocus

祝你好运

于 2013-04-11T17:38:24.603 回答