wsturdev
asked on
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?
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?
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.
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
VB has a much more limited list, such as vbYellow, which has the same value as wdColorYellow
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.
ASKER
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?
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?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.