繁体   English   中英

如何在单词文档中找到特定单词并使用vba代码将单词粘贴到单词附近?

[英]How to find a specific word in a word document and paste a word near to that using vba code?

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

我已经打开了文档,所以我只想查找单词并将其粘贴到该单词附近。 我已经使用movedown和moveright方法完成了这个操作,但是它更多地取决于光标的位置。

谢谢,

巴拉提

我在访问中使用它,我不知道它是否对您有用。

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

祝好运

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM