Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Microsoft Office > Access and Access VBA > Access VBA
|
Access VBA Discuss using VBA for Access programming.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Access VBA section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old January 28th, 2004, 01:20 AM
Registered User
 
Join Date: Dec 2003
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
Default macro for finding multiple words

Hello All,

i want to find two words namely w1 and w2 in a word document
using a macro.And also want them to be highlighted.

If anyone knows the code for the macro, pls let me know.
 
Old January 28th, 2004, 10:36 AM
Friend of Wrox
 
Join Date: Jul 2003
Posts: 174
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Although this forum is for Access VBA, Word is easier to create macros. While you have Word open, you can 'record' a macro. Go to Tools > Macro > Record. Take the steps necessary to obtain the objective. Meaning, click CTRL+H. Enter w1 as the search criteria. Enter w1 as the Replace value. Click More >>, Format and then Font. Select the font color to change your item (I selected Red). Click Replace All. After replacing has finished, change the w1 values to w2 and run again. Stop the macro. This is what it should generate:
Sub FindChangeFont()
'
' FindChangeFont Macro
' Macro recorded 1/28/2004 by Beth Moffitt
'
    Selection.Find.ClearFormatting
    Selection.Find.Replacement.ClearFormatting
    With Selection.Find
        .Text = "w1"
        .Replacement.Text = "w1"
        .Forward = True
        .Wrap = wdFindContinue
        .Format = True
        .MatchCase = False
        .MatchWholeWord = False
        .MatchWildcards = False
        .MatchSoundsLike = False
        .MatchAllWordForms = False
    End With
    Selection.Find.Execute Replace:=wdReplaceAll
    With Selection.Find
        .Text = "w2"
        .Replacement.Text = "w2"
        .Forward = True
        .Wrap = wdFindContinue
        .Format = True
        .MatchCase = False
        .MatchWholeWord = False
        .MatchWildcards = False
        .MatchSoundsLike = False
        .MatchAllWordForms = False
    End With
    Selection.Find.Execute Replace:=wdReplaceAll
End Sub

Regards,

Beth M
 
Old January 30th, 2004, 02:42 AM
Registered User
 
Join Date: Dec 2003
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
Default

got by adding the following code
Selection.Find.Replacement.Font.Color = wdColorBlue for highlighting in blue color.

thanks........





Similar Threads
Thread Thread Starter Forum Replies Last Post
calling to xlam macro from macro inside xlsb SteveB Excel VBA 0 June 30th, 2008 06:43 PM
Trimming Words Nicky_uk Classic ASP Databases 5 February 21st, 2008 02:06 PM
search for multiple words keph Beginning PHP 5 April 6th, 2004 01:23 PM
Strange error when running macro in multiple files medaugh Excel VBA 0 September 15th, 2003 11:06 AM
Selecting multiple words in Word 2000 jdsturm98 Beginning VB 6 0 September 3rd, 2003 03:49 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.