Solved

how to use Find&Replace Object from WORD

Posted on 2000-05-07
4
160 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 50 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

Suggested Solutions

Title # Comments Views Activity
Macro which automatically sends attachment to Outlook 14 81
using Access 8 83
fso.FolderExists("\\server\HiddenFolder$") 4 87
VB script to continue despite error 2 48
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…
This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
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 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…

740 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