Results 1 to 6 of 6
  1. #1
    Lounger
    Join Date
    Aug 2003
    Posts
    32
    Thanks
    0
    Thanked 0 Times in 0 Posts

    How can i change the color of a word in a document (word 2000, word 97)

    How do I change the color of a word in a Word document? Thsi word appears multiple times in my document, i want to change the color of all instances of that word.

    Thanks in advance...

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: How can i change the color of a word in a document (word 2000, word 97

    Something like this:

    Sub ColorWord(sWord As String, lColor As Long)
    With ActiveDocument.Content.Find
    .ClearFormatting
    .Replacement.ClearFormatting
    .Text = sWord
    .Replacement.Text = "^&"
    .Replacement.Font.Color = lColor
    .Forward = True
    .Wrap = wdFindContinue
    .Format = True
    .MatchCase = False
    .MatchWholeWord = True
    .MatchWildcards = False
    .MatchSoundsLike = False
    .MatchAllWordForms = False
    .Execute Replace:=wdReplaceAll
    End With
    End Sub

    Call it as follows:

    ColorWord "astute", wdColorRed

    The macro as written will only color whole words, not parts of words. In the example, "astuteness" wouldn't be colored. If you prefer, change .MatchWholeWord = True to .MatchWholeWord = False; you can also change some of the other settings if you like.

    Note: the core of the macro was recorded; I cleaned it up a little bit and added the arguments to make it more general.

  3. #3
    Plutonium Lounger
    Join Date
    Nov 2001
    Posts
    10,550
    Thanks
    0
    Thanked 7 Times in 7 Posts

    Re: How can i change the color of a word in a document (word 2000, word 97

    Or if you don't need a macro then just use Edit > Replace. Put your word in the "Find What" box. Click on the more button, in the replace with box put Special > Find What Text and then Format Colour and chose the colour you want. They click Replace All.

    StuartR

  4. #4
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: How can i change the color of a word in a document (word 2000, word 97

    Of course, that is the action I recorded to create the macro I posted. But I assumed that the poster wanted code, since she asked this in the VBA forum and since she has been asking how to do things in Word VBA recently.

  5. #5
    Plutonium Lounger
    Join Date
    Nov 2001
    Posts
    10,550
    Thanks
    0
    Thanked 7 Times in 7 Posts

    Re: How can i change the color of a word in a document (word 2000, word 97

    Hans,

    Elementary my dear chap!
    Why are you always 2 steps ahead of me?

    StuartR

  6. #6
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: How can i change the color of a word in a document (word 2000, word 97

    Actually, it's one hour <img src=/S/grin.gif border=0 alt=grin width=15 height=15>

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •