Determining Font Colour

G

Gordon Bentley-Mix

G'day!

I'm working on a little tool that presents key information about the styles
in a document in a more user-friendly format. One of the data points I want
to provide is the font colour. I've read heaps about changing the colour of
various things - bits of text, graphs, even fonts - but I haven't seen
anything about determining what the colour of a font is currently. If I use
the value of the .Color property of the Font object, it gives me _really_
useful things like: -16777216 for Automatic; 255 for Red; 16711680 for Blue;
etc. Unfortunately, I don't think too many of my users are going to
understand this. <g>

Is there an easy way to "translate" the .Color values into something that a
wetware-based system can make sense of? I'd be happy with just the wdColor
constants and show anything else as "Custom".
--
Cheers!
Gordon

Uninvited email contact will be marked as SPAM and ignored. Please post all
follow-ups to the newsgroup.
 
M

macropod

Hi Gordon,

If you look up ColorIndex in Word's help file, you'll see a list of the standard colour set (WdColorIndex constants). In theory, you
should be able to use this test whether the selected font's colour is in the colorindex, via something like:

Sub FontColourTest()
Dim col As String
Select Case Selection.Characters(1).Font.ColorIndex
Case 0
col = "wdAuto"
Case 1
col = "wdBlack"
Case 2
col = "wdBlue"
Case 3
col = "wdTurquoise"
Case 4
col = "wdBrightGreen"
Case 5
col = "wdPink"
Case 6
col = "wdRed"
Case 7
col = "wdYellow"
Case 8
col = "wdWhite"
Case 9
col = "wdDarkBlue"
Case 10
col = "wdTeal"
Case 11
col = "wdGreen"
Case 12
col = "wdViolet"
Case 13
col = "wdDarkRed"
Case 14
col = "wdDarkYellow"
Case 15
col = "wdGray50"
Case 16
col = "wdGray25"
Case Else
col = vbCrLf & "not in the Word ColorIndex"
End Select
MsgBox "The first selected character's colour is " & col
End Sub

However, in Word 2000 at least, I get false matches between the colours shown on the standard font palette and the colorindex (eg
'Tan' is returned as 'wdYellow'). This also happens with custom colours.

Note that the above code can't return a meaningful colour is characters
 
G

Gordon Bentley-Mix

Hmm... I understand your approach, and I think maybe I can adapt it to my
needs using the WdColor constants rather than the WdColorIndex constants.
I've done something similar with the .Bold, .Italic and .Underline properties
(which return 0 or -1) and the .Alignment property of the ParagraphFormat
object (which returns 0, 1, 2 or 3).

I'll give it a shot.

BTW, I think the reason why you're getting false matches with the ColorIndex
is explained here:

http://www.wordarticles.com/Articles/Colours/2003.htm

--
Cheers!
Gordon

Uninvited email contact will be marked as SPAM and ignored. Please post all
follow-ups to the newsgroup.


macropod said:
Hi Gordon,

If you look up ColorIndex in Word's help file, you'll see a list of the standard colour set (WdColorIndex constants). In theory, you
should be able to use this test whether the selected font's colour is in the colorindex, via something like:

Sub FontColourTest()
Dim col As String
Select Case Selection.Characters(1).Font.ColorIndex
Case 0
col = "wdAuto"
Case 1
col = "wdBlack"
Case 2
col = "wdBlue"
Case 3
col = "wdTurquoise"
Case 4
col = "wdBrightGreen"
Case 5
col = "wdPink"
Case 6
col = "wdRed"
Case 7
col = "wdYellow"
Case 8
col = "wdWhite"
Case 9
col = "wdDarkBlue"
Case 10
col = "wdTeal"
Case 11
col = "wdGreen"
Case 12
col = "wdViolet"
Case 13
col = "wdDarkRed"
Case 14
col = "wdDarkYellow"
Case 15
col = "wdGray50"
Case 16
col = "wdGray25"
Case Else
col = vbCrLf & "not in the Word ColorIndex"
End Select
MsgBox "The first selected character's colour is " & col
End Sub

However, in Word 2000 at least, I get false matches between the colours shown on the standard font palette and the colorindex (eg
'Tan' is returned as 'wdYellow'). This also happens with custom colours.

Note that the above code can't return a meaningful colour is characters

--
Cheers
macropod
[MVP - Microsoft Word]


Gordon Bentley-Mix said:
G'day!

I'm working on a little tool that presents key information about the styles
in a document in a more user-friendly format. One of the data points I want
to provide is the font colour. I've read heaps about changing the colour of
various things - bits of text, graphs, even fonts - but I haven't seen
anything about determining what the colour of a font is currently. If I use
the value of the .Color property of the Font object, it gives me _really_
useful things like: -16777216 for Automatic; 255 for Red; 16711680 for Blue;
etc. Unfortunately, I don't think too many of my users are going to
understand this. <g>

Is there an easy way to "translate" the .Color values into something that a
wetware-based system can make sense of? I'd be happy with just the wdColor
constants and show anything else as "Custom".
--
Cheers!
Gordon

Uninvited email contact will be marked as SPAM and ignored. Please post all
follow-ups to the newsgroup.
 
G

Gordon Bentley-Mix

Not pretty but it works:

<SNIP>
With .Font
<SNIP>
Select Case .Color
Case wdColorGray05
StylesArray(7, StyleCount) = "5% Grey"
Case wdColorGray10
StylesArray(7, StyleCount) = "10% Grey"
Case wdColorGray125
StylesArray(7, StyleCount) = "12.5% Grey"
Case wdColorGray15
StylesArray(7, StyleCount) = "15% Grey"
Case wdColorGray20
StylesArray(7, StyleCount) = "20% Grey"
Case wdColorGray30
StylesArray(7, StyleCount) = "30% Grey"
Case wdColorGray35
StylesArray(7, StyleCount) = "35% Grey"
Case wdColorGray375
StylesArray(7, StyleCount) = "37.5% Grey"
Case wdColorGray40
StylesArray(7, StyleCount) = "40% Grey"
Case wdColorGray45
StylesArray(7, StyleCount) = "45% Grey"
Case wdColorGray50
StylesArray(7, StyleCount) = "50% Grey"
Case wdColorGray55
StylesArray(7, StyleCount) = "55% Grey"
Case wdColorGray60
StylesArray(7, StyleCount) = "60% Grey"
Case wdColorGray625
StylesArray(7, StyleCount) = "62.5% Grey"
Case wdColorGray65
StylesArray(7, StyleCount) = "65% Grey"
Case wdColorGray70
StylesArray(7, StyleCount) = "70% Grey"
Case wdColorGray75
StylesArray(7, StyleCount) = "75% Grey"
Case wdColorGray85
StylesArray(7, StyleCount) = "85% Grey"
Case wdColorGray90
StylesArray(7, StyleCount) = "90% Grey"
Case wdColorGray80
StylesArray(7, StyleCount) = "80% Grey"
Case wdColorGray875
StylesArray(7, StyleCount) = "87.5% Grey"
Case wdColorGray95
StylesArray(7, StyleCount) = "95% Grey"
Case wdColorIndigo
StylesArray(7, StyleCount) = "Indigo"
Case wdColorLightBlue
StylesArray(7, StyleCount) = "Light Blue"
Case wdColorLightOrange
StylesArray(7, StyleCount) = "Light Orange"
Case wdColorLightYellow
StylesArray(7, StyleCount) = "Light Yellow"
Case wdColorOliveGreen
StylesArray(7, StyleCount) = "Olive Green"
Case wdColorPaleBlue
StylesArray(7, StyleCount) = "Pale Blue"
Case wdColorPlum
StylesArray(7, StyleCount) = "Plum"
Case wdColorRed
StylesArray(7, StyleCount) = "Red"
Case wdColorRose
StylesArray(7, StyleCount) = "Rose"
Case wdColorSeaGreen
StylesArray(7, StyleCount) = "Sea Green"
Case wdColorSkyBlue
StylesArray(7, StyleCount) = "Sky Blue"
Case wdColorTan
StylesArray(7, StyleCount) = "Tan"
Case wdColorTurquoise
StylesArray(7, StyleCount) = "Turquoise"
Case wdColorViolet
StylesArray(7, StyleCount) = "Violet"
Case wdColorWhite
StylesArray(7, StyleCount) = "White"
Case wdColorYellow
StylesArray(7, StyleCount) = "Yellow"
Case wdColorAqua
StylesArray(7, StyleCount) = "Aqua"
Case wdColorAutomatic
StylesArray(7, StyleCount) = "Automatic"
Case wdColorBlack
StylesArray(7, StyleCount) = "Black"
Case wdColorBlue
StylesArray(7, StyleCount) = "Blue"
Case wdColorBlueGray
StylesArray(7, StyleCount) = "Blue Grey"
Case wdColorBrightGreen
StylesArray(7, StyleCount) = "Bright Green"
Case wdColorBrown
StylesArray(7, StyleCount) = "Brown"
Case wdColorDarkBlue
StylesArray(7, StyleCount) = "Dark Blue"
Case wdColorDarkGreen
StylesArray(7, StyleCount) = "Dark Green"
Case wdColorDarkRed
StylesArray(7, StyleCount) = "Dark Red"
Case wdColorDarkTeal
StylesArray(7, StyleCount) = "Dark Teal"
Case wdColorDarkYellow
StylesArray(7, StyleCount) = "Dark Yellow"
Case wdColorGold
StylesArray(7, StyleCount) = "Gold"
Case wdColorGreen
StylesArray(7, StyleCount) = "Green"
Case wdColorLavender
StylesArray(7, StyleCount) = "Lavender"
Case wdColorLightGreen
StylesArray(7, StyleCount) = "Light Green"
Case wdColorLightTurquoise
StylesArray(7, StyleCount) = "Light Turquoise"
Case wdColorLime
StylesArray(7, StyleCount) = "Lime"
Case wdColorOrange
StylesArray(7, StyleCount) = "Orange"
Case wdColorPink
StylesArray(7, StyleCount) = "Pink"
Case Else
StylesArray(7, StyleCount) = "Custom"
End Select
End With
<SNIP>

This behind a UserForm that collects the various data points about the InUse
styles and uses the style NameLocal as values in a ComboBox. All of the date
points get displayed in related TextBoxes on the UserForm when the user
selects a style from the ComboBox and clicks a button.

Partial code:

Private Sub btnViewDetails_Click()
Dim Idx As Integer
Idx = cboStylesList.ListIndex
<SNIP>
txtFontColour.Value = StylesArray(7, Idx)
<SNIP>
End Sub

Also has code to print this info in a new doc.

Note that this is very much a WIP, so don't pay too much attention to the
details. I'm just trying to work out how to collect the info at this point; I
figure out what to do with it later.

Anyway, thanks for pointing me in the right direction. I was hoping it would
be simple but I had a feeling it might be something like this.
--
Cheers!
Gordon

Uninvited email contact will be marked as SPAM and ignored. Please post all
follow-ups to the newsgroup.


macropod said:
Hi Gordon,

If you look up ColorIndex in Word's help file, you'll see a list of the standard colour set (WdColorIndex constants). In theory, you
should be able to use this test whether the selected font's colour is in the colorindex, via something like:

Sub FontColourTest()
Dim col As String
Select Case Selection.Characters(1).Font.ColorIndex
Case 0
col = "wdAuto"
Case 1
col = "wdBlack"
Case 2
col = "wdBlue"
Case 3
col = "wdTurquoise"
Case 4
col = "wdBrightGreen"
Case 5
col = "wdPink"
Case 6
col = "wdRed"
Case 7
col = "wdYellow"
Case 8
col = "wdWhite"
Case 9
col = "wdDarkBlue"
Case 10
col = "wdTeal"
Case 11
col = "wdGreen"
Case 12
col = "wdViolet"
Case 13
col = "wdDarkRed"
Case 14
col = "wdDarkYellow"
Case 15
col = "wdGray50"
Case 16
col = "wdGray25"
Case Else
col = vbCrLf & "not in the Word ColorIndex"
End Select
MsgBox "The first selected character's colour is " & col
End Sub

However, in Word 2000 at least, I get false matches between the colours shown on the standard font palette and the colorindex (eg
'Tan' is returned as 'wdYellow'). This also happens with custom colours.

Note that the above code can't return a meaningful colour is characters

--
Cheers
macropod
[MVP - Microsoft Word]


Gordon Bentley-Mix said:
G'day!

I'm working on a little tool that presents key information about the styles
in a document in a more user-friendly format. One of the data points I want
to provide is the font colour. I've read heaps about changing the colour of
various things - bits of text, graphs, even fonts - but I haven't seen
anything about determining what the colour of a font is currently. If I use
the value of the .Color property of the Font object, it gives me _really_
useful things like: -16777216 for Automatic; 255 for Red; 16711680 for Blue;
etc. Unfortunately, I don't think too many of my users are going to
understand this. <g>

Is there an easy way to "translate" the .Color values into something that a
wetware-based system can make sense of? I'd be happy with just the wdColor
constants and show anything else as "Custom".
--
Cheers!
Gordon

Uninvited email contact will be marked as SPAM and ignored. Please post all
follow-ups to the newsgroup.
 
M

macropod

Hi Gordon,

Yes, you could do that - there's 60 Color constants, which you could test with something like:

Sub FontColorTest()
Dim col As String
Select Case Selection.Characters(1).Font.Color
Case 13421619
col = "Aqua"
Case -16777216
col = "Automatic"
Case 0
col = "Black"
Case 16711680
col = "Blue"
Case 10053222
col = "Blue Gray"
Case 65280
col = "Bright Green"
Case 13209
col = "Brown"
Case 8388608
col = "Dark Blue"
Case 13056
col = "Dark Green"
Case 128
col = "Dark Red"
Case 6697728
col = "Dark Teal"
Case 32896
col = "Dark Yellow"
Case 52479
col = "Gold"
Case 15987699
col = "Gray 5%"
Case 15132390
col = "Gray 10%"
Case 14737632
col = "Gray 12.5%"
Case 14277081
col = "Gray 15%"
Case 13421772
col = "Gray 20%"
Case 12632256
col = "Gray 25%"
Case 11776947
col = "Gray 30%"
Case 10921638
col = "Gray 35%"
Case 10526880
col = "Gray 37.5%"
Case 10066329
col = "Gray 40%"
Case 9211020
col = "Gray 45%"
Case 8421504
col = "Gray 50%"
Case 7566195
col = "Gray 55%"
Case 6710886
col = "Gray 60%"
Case 6316128
col = "Gray 62.5%"
Case 5855577
col = "Gray 65%"
Case 5000268
col = "Gray 70%"
Case 4210752
col = "Gray 75%"
Case 3355443
col = "Gray 80%"
Case 2500134
col = "Gray 85%"
Case 2105376
col = "Gray 87.5%"
Case 1644825
col = "Gray 90%"
Case 789516
col = "Gray 95%"
Case 32768
col = "Green"
Case 10040115
col = "Indigo"
Case 16751052
col = "Lavender"
Case 16737843
col = "Light Blue"
Case 13434828
col = "Light Green"
Case 39423
col = "Light Orange"
Case 16777164
col = "Light Turquoise"
Case 10092543
col = "Light Yellow"
Case 52377
col = "Lime"
Case 13107
col = "Olive Green"
Case 26367
col = "Orange"
Case 16764057
col = "Pale Blue"
Case 16711935
col = "Pink"
Case 6697881
col = "Plum"
Case 255
col = "Red"
Case 13408767
col = "Rose"
Case 6723891
col = "Sea Green"
Case 16763904
col = "Sky Blue"
Case 10079487
col = "Tan"
Case 8421376
col = "Teal"
Case 16776960
col = "Turquoise"
Case 8388736
col = "Violet"
Case 16777215
col = "White"
Case 65535
col = "Yellow"
Case Else
col = vbCrLf & Selection.Characters(1).Font.Color & " (not a Word Color Constant)"
End Select
MsgBox "The first selected character's color is " & col
End Sub

I found the above constants under 'wdColor' at: http://msdn.microsoft.com/en-us/library/aa211923(office.11).aspx.

Thanks for the link confirming the ColorIndex foibles.

--
Cheers
macropod
[MVP - Microsoft Word]


Gordon Bentley-Mix said:
Hmm... I understand your approach, and I think maybe I can adapt it to my
needs using the WdColor constants rather than the WdColorIndex constants.
I've done something similar with the .Bold, .Italic and .Underline properties
(which return 0 or -1) and the .Alignment property of the ParagraphFormat
object (which returns 0, 1, 2 or 3).

I'll give it a shot.

BTW, I think the reason why you're getting false matches with the ColorIndex
is explained here:

http://www.wordarticles.com/Articles/Colours/2003.htm

--
Cheers!
Gordon

Uninvited email contact will be marked as SPAM and ignored. Please post all
follow-ups to the newsgroup.


macropod said:
Hi Gordon,

If you look up ColorIndex in Word's help file, you'll see a list of the standard colour set (WdColorIndex constants). In theory,
you
should be able to use this test whether the selected font's colour is in the colorindex, via something like:

Sub FontColourTest()
Dim col As String
Select Case Selection.Characters(1).Font.ColorIndex
Case 0
col = "wdAuto"
Case 1
col = "wdBlack"
Case 2
col = "wdBlue"
Case 3
col = "wdTurquoise"
Case 4
col = "wdBrightGreen"
Case 5
col = "wdPink"
Case 6
col = "wdRed"
Case 7
col = "wdYellow"
Case 8
col = "wdWhite"
Case 9
col = "wdDarkBlue"
Case 10
col = "wdTeal"
Case 11
col = "wdGreen"
Case 12
col = "wdViolet"
Case 13
col = "wdDarkRed"
Case 14
col = "wdDarkYellow"
Case 15
col = "wdGray50"
Case 16
col = "wdGray25"
Case Else
col = vbCrLf & "not in the Word ColorIndex"
End Select
MsgBox "The first selected character's colour is " & col
End Sub

However, in Word 2000 at least, I get false matches between the colours shown on the standard font palette and the colorindex (eg
'Tan' is returned as 'wdYellow'). This also happens with custom colours.

Note that the above code can't return a meaningful colour is characters

--
Cheers
macropod
[MVP - Microsoft Word]


Gordon Bentley-Mix said:
G'day!

I'm working on a little tool that presents key information about the styles
in a document in a more user-friendly format. One of the data points I want
to provide is the font colour. I've read heaps about changing the colour of
various things - bits of text, graphs, even fonts - but I haven't seen
anything about determining what the colour of a font is currently. If I use
the value of the .Color property of the Font object, it gives me _really_
useful things like: -16777216 for Automatic; 255 for Red; 16711680 for Blue;
etc. Unfortunately, I don't think too many of my users are going to
understand this. <g>

Is there an easy way to "translate" the .Color values into something that a
wetware-based system can make sense of? I'd be happy with just the wdColor
constants and show anything else as "Custom".
--
Cheers!
Gordon

Uninvited email contact will be marked as SPAM and ignored. Please post all
follow-ups to the newsgroup.
 

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