0

I have the following codes

  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

The above works fine and i have added the following in the above vba codes and its not working

With wdDoc.Content.Find
  .Text = "Date:"
  .Replacement.Text = "Datetest"
   Text = "Prime Lending Rate"
  .Replacement.Text =" Repo Rate"
  .Wrap = wdFindContinue
  .Execute Replace:=wdReplaceAll

Your help will be highly appreciated

Thanks

2
  • 1. You will have to use a loop if you want to replace multiple text 2. You are missing a . (DOT) before the 2nd Text. Change Text = "Prime Lending Rate" to .Text = "Prime Lending Rate" Commented Jan 21, 2021 at 4:41
  • No, the OP doesn't need a loop, Commented Jan 21, 2021 at 6:45

1 Answer 1

1

You need to have:

.Execute Replace:=wdReplaceAll

between each set of F/R expressions, thus:

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
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.