ID: Q89853
The information in this article applies to:
The Microsoft WordBasic CharColor statement sets the character color of the selection to the color specified in the Color argument. The CharColor() function returns the color of the selected text.
For more information about setting or retrieving font color values for Word 97 for Windows or Word 98 Macintosh Edition, while in the Visual Basic for Applications Editor click the Office Assistant, type "ColorIndex," click Search, and then click to view "ColorIndex Property."
WARNING: ANY USE BY YOU OF THE CODE PROVIDED IN THIS ARTICLE IS AT YOUR OWN RISK. Microsoft provides this macro code "as is" without warranty of any kind, either express or implied, including but not limited to the implied warranties of merchantability and/or fitness for a particular purpose.
CharColor <Color>
The color argument is a numeric code for one of the following character colors supported in Word 2.0 and 6.0 for Windows:
  Color Code  Color Name
  ----------  ----------
 
  0           Auto (color specified by the Control Panel setting)
  1           Black
  2           Blue
  3           Cyan
  4           Green
  5           Magenta
  6           Red
  7           Yellow
  8           White
  9           Dark Blue
 10           Dark Cyan
 11           Dark Green
 12           Dark Magenta
 13           Dark Red
 14           Dark Yellow
 15           Dark Gray
 16           Light Gray
The function form of CharColor returns the same number codes set by the
CharColor statement or the value -1 if all the selected text is not the
same color. Below is an example of the function form of CharColor:
   Sub MAIN
      n = CharColor()
      If n = - 1 Then Print "More than one color is used in the selection"
   End Sub
The following macro inserts the word "Color" formatted for each of the 16
colors available using the CharColor command in Word version 2.0 and 6.0
for Windows:
   Sub MAIN
      For count = 1 To 16
         Insert "Color"
         WordLeft 1, 1
         CharColor count
         CharRight
         InsertPara
      Next
   End Sub
The CharColor command under Word for Windows versions 1.x supports eight
character colors, as outlined below:
 Color Code   Color Name
 ----------   -----------
 0            Auto (color specified by the Control Panel setting)
 1            Black
 2            Blue
 3            Cyan
 4            Green
 5            Magenta
 6            Red
 7            Yellow
 8            White
The following sample macro inserts the word "Color" formatted for each of
the 8 colors available using the CharColor command in Word for Windows
versions 1.x:
   Sub MAIN
      For count = 0 To 8
         Insert "Color"
         WordLeft 1, 1
         CharColor count
         CharRight
         InsertPara
      Next
   End Sub
"Using WordBasic," by WexTech Systems and Microsoft, pages 159-160
"Microsoft Word for Windows and OS/2 Technical Reference," pages 137-138
Additional query words: charcolor character color
Keywords          : kbmacro wordnt kbmacroexample winword ntword macword word6 winword2 word7 word95 
Version           : WINDOWS:1.0,1.1,1.1a,2.0,2.0a,2.0a- CD,2.0b,2.0c,6.0,6.0a,6.0c,7.0,7.0a; MACINTOSH:6.0,6.0.1,6.0.1a
Platform          : MACINTOSH Win95 WINDOWS winnt
Issue type        : kbinfo
Last Reviewed: February 4, 1998