查找文本并替换文本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 SettingsOwnerMy DocumentsdownloadsworkM-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 SettingsOwnerMy DocumentsdownloadsworkM-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

最新更新