如何解决查找文本并替换文本 excel word vba
Sub DocSearch()
Dim wdApp As Object,wdDoc As Object
Set wdApp = CreateObject("word.application")
wdApp.Visible = True
Set wdDoc = wdApp.Documents.Open("C:\Documents and Settings\Owner\My Documents\downloads\work\M-F-380.1.doc")
With wdDoc.Content.Find
.Text = "Date:"
.Replacement.Text = "Datetest"
.Wrap = wdFindContinue
.Execute Replace:=wdReplaceAll
End With
Set wdApp = nothing: Set wdDoc = nothing
End Sub
以上工作正常,我在上面的 vba 代码中添加了以下内容,但它不起作用
With wdDoc.Content.Find
.Text = "Date:"
.Replacement.Text = "Datetest"
Text = "Prime Lending Rate"
.Replacement.Text =" Repo Rate"
.Wrap = wdFindContinue
.Execute Replace:=wdReplaceAll
非常感谢您的帮助
谢谢
解决方法
你需要:
.Execute Replace:=wdReplaceAll
在每组 F/R 表达式之间,因此:
Sub DocSearch()
Dim wdApp As Object,wdDoc As Object
Set wdApp = CreateObject("word.application")
wdApp.Visible = True
Set wdDoc = wdApp.Documents.Open("C:\Documents and Settings\Owner\My Documents\downloads\work\M-F-380.1.doc")
With wdDoc.Content.Find
.Wrap = wdFindContinue
.Text = "Date:"
.Replacement.Text = "Datetest"
.Execute Replace:=wdReplaceAll
.Text = "Prime Lending Rate"
.Replacement.Text = " Repo Rate"
.Execute Replace:=wdReplaceAll
End With
Set wdApp = Nothing: Set wdDoc = Nothing
End Sub
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。