• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 976
  • Last Modified:

Word Colors

I have a table with color names:

wdColorYellow
wdColorBlue
wdColorBrightGreen

and so on

I open the table and run through a loop.  Based upon criteria, I need to color certain cells of a word table (I am doing this from Access).

if I use this code, specifying the color directly, it works:
                With wdApp.Selection.Cells
                    With .Shading
                        .Texture = wdTextureNone
                        .ForegroundPatternColor = wdColorAutomatic
                        .BackgroundPatternColor = wdColorBrightGreen
                    End With
                End With

But what I want to do is this:

                With wdApp.Selection.Cells
                    With .Shading
                        .Texture = wdTextureNone
                        .ForegroundPatternColor = wdColorAutomatic
                        .BackgroundPatternColor = myTable1!Word_Color_Name
                    End With
                End With

I get a Type Mismatch error.

How can I do this?  Alternatively, where can I find a list of word colors and their associated Color Index numbers so I can use those?

0
wsturdev
Asked:
wsturdev
  • 4
1 Solution
 
GrahamSkanCommented:
You can get a list of Word.Color constants in the VBA editor, by choosing View/Object Browser. Select Word in the top dropdown, and scroll the Classes pane until you get to the wdColor entry. Select it and the list will appear in the right-hand pane.
0
 
GrahamSkanCommented:
The constant must be a Long Integer, as colours always are in Windows.
VB has a much more limited list, such as vbYellow, which has the same value as wdColorYellow
0
 
GrahamSkanCommented:
Note that there is also a wdColorIndex type of constant which can apply to a ...ColorIndex property. This is a predefined list of 'solid' colours to which text is usually limited.
0
 
wsturdevAuthor Commented:
I did as suggested in your first response, and I see the list of colors.  That is what I have in my table.  Now how do I use the name of the color as listed in the table in a statement?

if I say:

                       .BackgroundPatternColor = wdColorBrightGreen
 it sets the cell to bright green, but I have to hard code wdColorBrightGreen

Instead, I want to have a field in Table1 called Word_Color_Name.  Each row of the table will have one entry from the list of color constants.  How do I retrieve the color constant "wdColorBrightGreen" from the field Word_Color_Name and use it dynamically in a statement, as in=:

                        .BackgroundPatternColor = myTable1!Word_Color_Name


I understand your second post.  Now, is there a place I can look so I can find out what the long integer value is that corresponds to wdColorBrightGreen?

0
 
GrahamSkanCommented:
You will have to use a funtion with a series of select statements.
I have just written this by copying the list from the Word VBA Help file and editing it with Word's Find and Replace, using wildcards.
Function GetColourValue(strName As String) As WdColor
    Dim lValue As Long
    Select Case strName
        Case "wdColorGray625"
            lValue = wdColorGray625
        Case "wdColorGray70"
            lValue = wdColorGray70
        Case "wdColorGray80"
            lValue = wdColorGray80
        Case "wdColorGray875"
            lValue = wdColorGray875
        Case "wdColorGray95"
            lValue = wdColorGray95
        Case "wdColorIndigo"
            lValue = wdColorIndigo
        Case "wdColorLightBlue"
            lValue = wdColorLightBlue
        Case "wdColorLightOrange"
            lValue = wdColorLightOrange
        Case "wdColorLightYellow"
            lValue = wdColorLightYellow
        Case "wdColorOliveGreen"
            lValue = wdColorOliveGreen
        Case "wdColorPaleBlue"
            lValue = wdColorPaleBlue
        Case "wdColorPlum"
            lValue = wdColorPlum
        Case "wdColorRed"
            lValue = wdColorRed
        Case "wdColorRose"
            lValue = wdColorRose
        Case "wdColorSeaGreen"
            lValue = wdColorSeaGreen
        Case "wdColorSkyBlue"
            lValue = wdColorSkyBlue
        Case "wdColorTan"
            lValue = wdColorTan
        Case "wdColorTeal"
            lValue = wdColorTeal
        Case "wdColorTurquoise"
            lValue = wdColorTurquoise
        Case "wdColorViolet"
            lValue = wdColorViolet
        Case "wdColorWhite"
            lValue = wdColorWhite
        Case "wdColorYellow"
            lValue = wdColorYellow
        Case "wdColorAqua"
            lValue = wdColorAqua
        Case "wdColorAutomatic"
            lValue = wdColorAutomatic
        Case "wdColorBlack"
            lValue = wdColorBlack
        Case "wdColorBlue"
            lValue = wdColorBlue
        Case "wdColorBlueGray"
            lValue = wdColorBlueGray
        Case "wdColorBrightGreen"
            lValue = wdColorBrightGreen
        Case "wdColorBrown"
            lValue = wdColorBrown
        Case "wdColorDarkBlue"
            lValue = wdColorDarkBlue
        Case "wdColorDarkGreen"
            lValue = wdColorDarkGreen
        Case "wdColorDarkRed"
            lValue = wdColorDarkRed
        Case "wdColorDarkTeal"
            lValue = wdColorDarkTeal
        Case "wdColorDarkYellow"
            lValue = wdColorDarkYellow
        Case "wdColorGold"
            lValue = wdColorGold
        Case "wdColorGray05"
            lValue = wdColorGray05
        Case "wdColorGray10"
            lValue = wdColorGray10
        Case "wdColorGray125"
            lValue = wdColorGray125
        Case "wdColorGray15"
            lValue = wdColorGray15
        Case "wdColorGray20"
            lValue = wdColorGray20
        Case "wdColorGray25"
            lValue = wdColorGray25
        Case "wdColorGray30"
            lValue = wdColorGray30
        Case "wdColorGray35"
            lValue = wdColorGray35
        Case "wdColorGray375"
            lValue = wdColorGray375
        Case "wdColorGray40"
            lValue = wdColorGray40
        Case "wdColorGray45"
            lValue = wdColorGray45
        Case "wdColorGray50"
            lValue = wdColorGray50
        Case "wdColorGray55"
            lValue = wdColorGray55
        Case "wdColorGray60"
            lValue = wdColorGray60
        Case "wdColorGray65"
            lValue = wdColorGray65
        Case "wdColorGray75"
            lValue = wdColorGray75
        Case "wdColorGray85"
            lValue = wdColorGray85
        Case "wdColorGray90"
            lValue = wdColorGray90
        Case "wdColorGreen"
            lValue = wdColorGreen
        Case "wdColorLavender"
            lValue = wdColorLavender
        Case "wdColorLightGreen"
            lValue = wdColorLightGreen
        Case "wdColorLightTurquoise"
            lValue = wdColorLightTurquoise
        Case "wdColorLime"
            lValue = wdColorLime
        Case "wdColorOrange"
            lValue = wdColorOrange
    End Select
    GetColourValue = lValue
End Function


0

Featured Post

Upgrade your Question Security!

Add Premium security features to your question to ensure its privacy or anonymity. Learn more about your ability to control Question Security today.

  • 4
Tackle projects and never again get stuck behind a technical roadblock.
Join Now