[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now


find and replace string in ms word using vb.net

Posted on 2009-04-21
Medium Priority
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

Accepted Solution

devlinb earned 750 total points
ID: 24193675
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

ID: 31572690
Thank You

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

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…
In real business world data are crucial and sometimes data are shared among different information systems. Hence, an agreeable file transfer protocol need to be established.
When cloud platforms entered the scene, users and companies jumped on board to take advantage of the many benefits, like the ability to work and connect with company information from various locations. What many didn't foresee was the increased risk…
With just a little bit of  SQL and VBA, many doors open to cool things like synchronize a list box to display data relevant to other information on a form.  If you have never written code or looked at an SQL statement before, no problem! ...  give i…
Suggested Courses

872 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