Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Word / Programming / August 2007

Tip: Looking for answers? Try searching our database.

find and change font colour?

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Geoff Cox < - 24 Aug 2007 23:25 GMT
Hello,

I would like to use a macro to find all green fonted words and change
them to blue ones.

How to do this? A few pointers would be appreciated!

Thanks

Geoff
Greg Maxey - 25 Aug 2007 00:00 GMT
Geoff,

If you are only interested in the main text part of your document then
something like this will do:

Sub Scratchmacro()
Dim oRng As Word.Range
Set oRng = ActiveDocument.Range
With oRng.Find
 .Font.Color = wdColorGreen
 .Replacement.Font.Color = wdColorBlue
 .Execute Replace:=wdReplaceAll
End With
End Sub

If you are talking about "all" parts of the document e.g., headers,
foorters, textboxes, etc. then you will need a more complext macro that
process all the story ranges of the document.  See:
http://word.mvps.org/faqs/customization/ReplaceAnywhere.htm

Also note that in Word2007 what may appear to be font wdColorGreen actually
has a specific theme color number (I guess that is correct).  To find what
this number is, you will need to select a bit of the Green text and run this
code in the the VBE immediate window:

?Selection.Font.Color

The number returned can be used in place of wdColorGreen in the code above.

Signature

Greg Maxey/Word MVP
See:
http://gregmaxey.mvps.org/word_tips.htm
For some helpful tips using Word.

> Hello,
>
[quoted text clipped - 6 lines]
>
> Geoff
Geoff Cox < - 25 Aug 2007 07:26 GMT
>Geoff,
>
[quoted text clipped - 10 lines]
>End With
>End Sub

Thanks Greg!

The above works fine.

What I am trying to do is to find a series of section titles for which
the word or words has/have green fonts and to then give them a
particluar style called cgHeading.

The cgHeading style is listed under Word Styles and Formatting and is
part of the Course Genie program for changing Word docs into html
pages..

So far I have used record macro to simply change a green fonted word
to a cgHeadng style and get

Selection.Style = ActiveDocument.Styles("cgHeading")

How do I incorporate that into your code so that it will change one or
more green fonted words on a line into a cgHeading?

Cheers

Geoff

>If you are talking about "all" parts of the document e.g., headers,
>foorters, textboxes, etc. then you will need a more complext macro that
[quoted text clipped - 9 lines]
>
>The number returned can be used in place of wdColorGreen in the code above.
Graham Mayor - 25 Aug 2007 08:13 GMT
Greg has probably retired for the night by now - so use instead

Dim oRng As Word.Range
Set oRng = ActiveDocument.Range
With oRng.Find
   .Font.Color = wdColorGreen
   .Replacement.Style = "cgHeading"
   .Replacement.Font.Color = wdColorBlue
   .Execute replace:=wdReplaceAll
End With

Signature

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

My web site www.gmayor.com
Word MVP web site http://word.mvps.org
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>

>> Geoff,
>>
[quoted text clipped - 50 lines]
>> The number returned can be used in place of wdColorGreen in the code
>> above.
Geoff Cox < - 25 Aug 2007 08:27 GMT
>Greg has probably retired for the night by now - so use instead
>
[quoted text clipped - 6 lines]
>    .Execute replace:=wdReplaceAll
>End With

Wonderful! Thanks Graham.

Cheers

Geoff

Rate this thread:






 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.