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

x
?
Solved

find and replace string in ms word using vb.net

Posted on 2009-04-21
2
Medium Priority
?
1,275 Views
Last Modified: 2013-11-07
Hi..
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

0
Comment
Question by:jamiechris
2 Comments
 
LVL 2

Accepted Solution

by:
devlinb earned 750 total points
ID: 24193675
You could try something like this:
    wc.WordApp.Selection.WholeStory
    wc.WordApp.Selection.Find.ClearFormatting
    wc.WordApp.Selection.Find.Replacement.ClearFormatting
    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

0
 

Author Closing Comment

by:jamiechris
ID: 31572690
Thank You
0

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