Results 1 to 2 of 2

Thread: VBA to find text in Word, replace with multiple lines of text

  1. #1

    VBA to find text in Word, replace with multiple lines of text

    Having issues writing script to find a single tag, and replace it with multiple lines of text.

    I wrote some VBA to find a tag such as:


    And looking to replace it with something like below:

    <h2>Live Chat</h2>
    <p>A <a href="">research report</a> found that Live Chat was hands down the preferred method of communication for online shoppers when compared to other service channels. A <a href="">separate study</a> by the American Marketing Association states that customers that use live chat are three times more likely to make a purchase compared to those who don’t.</p><br>
    <p>a <b>Best practices</b> for live chat include:</p>

    The problem is it only replaces with the first line above: "<h2>Live Chat</h2>"

    Any ideas? Below is the chunk of code responsible for this (please note I am using excel to execute in Word):

    With WordDoc.Content.Find
     .Text = TagName
    .Replacement.Text = TagValue
    .Wrap = wdFindContinue
    .Execute Replace:=wdReplaceAll 'Find & Replace all instances
     End With
    This has been cross posted at

  2. #2
    Moderator VBAX Wizard SamT's Avatar
    Oct 2006
    Near Columbia
    Thread Moved to Word Forum
    I expect the student to do their homework and find all the errrors I leeve in.

    Please take the time to read the Forum FAQ

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts