问题描述
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