Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

how to use Find&Replace Object from WORD

Posted on 2000-05-07
4
Medium Priority
?
164 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

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

Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
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 utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
Suggested Courses

660 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