Microsoft KB Archive/89853

{|
 * width="100%"|

WD: WordBasic CharColor Defined

 * }

Q89853

-

The information in this article applies to:


 * Microsoft Word for Windows, versions 1.0, 1.1, 1.1a, 2.0, 2.0a, 2.0a-CD, 2.0b, 6.0, 6.0a, 6.0c
 * Microsoft Word for Windows NT, version 6.0
 * Microsoft Word for Windows, versions 7.0, 7.0a
 * Microsoft Word for the Macintosh, versions 6.0, 6.0.1, 6.0.1a

-

SUMMARY
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 &quot;ColorIndex,&quot; click Search, and then click to view &quot;ColorIndex Property.&quot;

MORE INFORMATION
WARNING: ANY USE BY YOU OF THE CODE PROVIDED IN THIS ARTICLE IS AT YOUR OWN RISK. Microsoft provides this macro code &quot;as is&quot; 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 Syntax
CharColor 

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 &quot;More than one color is used in the selection&quot; End Sub The following macro inserts the word &quot;Color&quot; 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 &quot;Color&quot; 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 &quot;Color&quot; 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 &quot;Color&quot; WordLeft 1, 1 CharColor count CharRight InsertPara Next End Sub