Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

how to use Find&Replace Object from WORD

Posted on 2000-05-07
4
Medium Priority
?
166 Views
Last Modified: 2012-05-04
how to use Find&Replace Object from WORD

In VB App I'm using the MS Word Object,
I'm trying to use the Find and Replace Object.
but I get 'Automation Error'

please send a sample code.

0
Comment
Question by:david2001
4 Comments
 
LVL 143

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 2785454
Please post your actual code.
0
 

Author Comment

by:david2001
ID: 2785461
this is a few methods i tried

Dim a As Boolean

1)
a = wordApp.ActiveDocument.Content.Find.Execute(FindText:=CurOrgSentence)

-----------------------------------
2)
a = wordApp.Selection.Find.Text = "and"
    ReplaceWith:=CurTarSentence, Replace:=wdReplaceOne

-----------------------------------          
3)

wordApp.ActiveDocument.Select
         
With wordApp.Selection.Find
..Text = "and"
..Forward = True
..ClearFormatting
..MatchWholeWord = True
..MatchCase = False
..Execute FindText:="To"
End With
0
 
LVL 6

Accepted Solution

by:
Marine earned 200 total points
ID: 2785572
With Selection.Find
    .Forward = True
    .Wrap = wdFindStop
    .Text = "Hello"
    .Execute
End With

Here is the Link with lots of examples

http://msdn.microsoft.com/library/officedev/office97/web/007.htm#CH007H105
0
 
LVL 44

Expert Comment

by:bruintje
ID: 2786068
or

Selection.Find.ClearFormatting
    With Selection.Find
        .Text = "rt"
        .Replacement.Text = "cb"
        .Forward = True
        'wdFinContinue will replace all
        'wdFindAsk will ask at each found
        'wdFindStop will stop after the first replacement
        .Wrap = wdFindContinue
        .MatchWholeWord = True
    End With
    Selection.Find.Execute Replace:=wdReplaceAll

HTH:O)Bruintje
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…

877 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