Solved

how to use Find&Replace Object from WORD

Posted on 2000-05-07
4
156 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 142

Expert Comment

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

Author Comment

by:david2001
Comment Utility
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 50 total points
Comment Utility
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
Comment Utility
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

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

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…
Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
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…

763 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

9 Experts available now in Live!

Get 1:1 Help Now