find and replace string in ms word using

Posted on 2009-04-21
Last Modified: 2013-11-07
Im trying to find a particular string in a word document and replace all with another string using VB.NET.
The following code Snippet is what i used. I get an error "The Stub received bad data" . Can any one give me a proper solution for this or is there any other way to do this.

While wc.WordApp.ActiveDocument.Content.Find.Execute(FindText:="customer", _ ReplaceWith:="subscriber", Replace:=Word.WdReplace.wdReplaceAll, _ Wrap:=Word.WdFindWrap.wdFindContinue)

End While

Open in new window

Question by:jamiechris
    LVL 2

    Accepted Solution

    You could try something like this:
        With wc.WordApp.Selection.Find
            .Text = "customer"
            .Replacement.Text = "subscriber"
            .Forward = True
            .Wrap = wdFindAsk
            .Format = False
            .MatchCase = False
            .MatchWholeWord = False
            .MatchWildcards = False
            .MatchSoundsLike = False
            .MatchAllWordForms = False
        End With
        wc.WordApp.Selection.Find.Execute Replace:=Word.WdReplace.wdReplaceAll

    Open in new window


    Author Closing Comment

    Thank You

    Featured Post

    How your wiki can always stay up-to-date

    Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
    - Increase transparency
    - Onboard new hires faster
    - Access from mobile/offline

    Join & Write a Comment

    It’s quite interesting for me as I worked with Excel using for some time. Here are some topics which I know want to share with others whom this might help. First of all if you are working with Excel then you need to Download the Following …
    Creating an analog clock UserControl seems fairly straight forward.  It is, after all, essentially just a circle with several lines in it!  Two common approaches for rendering an analog clock typically involve either manually calculating points with…
    how to add IIS SMTP to handle application/Scanner relays into office 365.
    Here's a very brief overview of the methods PRTG Network Monitor ( offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…

    746 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    13 Experts available now in Live!

    Get 1:1 Help Now