Is there macro that can look through a long Word document. If theword 'website' appears on a page, c

J

John

I am looking through a document, about 900 pages in length.

I'd love to be able to run a macro that, when it detects the word
'website' exists on a page, it colours all the text on that page
orange, for example.

Do any of you experts know if this is actually possible?


Thanks
 
G

Graham Mayor

Dim oPara As Paragraph
On Error Resume Next
For Each oPara In ActiveDocument.Paragraphs
If InStr(1, oPara.Range, "Website") <> 0 Then
oPara.Range.Select
oPara.Range.Bookmarks("\page").Range.Font.Color = wdColorOrange
End If
Next oPara

http://www.gmayor.com/installing_macro.htm

--
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Graham Mayor - Word MVP


<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
 
V

vik ram

Dim oPara As Paragraph
On Error Resume Next
For Each oPara In ActiveDocument.Paragraphs
    If InStr(1, oPara.Range, "Website") <> 0 Then
        oPara.Range.Select
        oPara.Range.Bookmarks("\page").Range.Font.Color = wdColorOrange
    End If
Next oPara

http://www.gmayor.com/installing_macro.htm

--
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Graham Mayor -  Word MVP

My web sitewww.gmayor.com
Word MVP web sitehttp://word.mvps.org
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>









- Show quoted text -

Thanks, though it didn't seem to do the trick....... EDIT: I changed
'Website' to 'website' and it worked! Thanks :)
 
G

Graham Mayor

I should have mentioned that the search is case sensitive :(

--
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Graham Mayor - Word MVP


<>>< ><<> ><<> <>>< ><<> <>>< <>><<>


Dim oPara As Paragraph
On Error Resume Next
For Each oPara In ActiveDocument.Paragraphs
If InStr(1, oPara.Range, "Website") <> 0 Then
oPara.Range.Select
oPara.Range.Bookmarks("\page").Range.Font.Color = wdColorOrange
End If
Next oPara

http://www.gmayor.com/installing_macro.htm

--
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Graham Mayor - Word MVP

My web sitewww.gmayor.com
Word MVP web sitehttp://word.mvps.org
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>









- Show quoted text -

Thanks, though it didn't seem to do the trick....... EDIT: I changed
'Website' to 'website' and it worked! Thanks :)
 
1

123Jim

Nice work Graham.

May I suggest changing this line :
If InStr(1, oPara.Range, "Website") <> 0 Then
to:
If InStr(1, LCase(oPara.Range), "website") <> 0 Then

I'm sure you notice "Website" is changed to "website" .... but with the
addition of LCase the matching is case blind.

cheers
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top