Cell shading always black

J

Jim Boyce

ActiveDocument.Tables(1).Cell(cellStart, 2).Shading.BackgroundPatternColor =
wdBlue

Always results in black cell shading, regardless of the color specified.
Anyone have thoughts as to why? Using BackgroundPatternColorIndex always
results in no shading.

Thanks,

Jim
 
H

Helmut Weber

Hi Jim,

take a close look at the object catalog.

wdblue (value = 2) is an element of the class wdcolorindex.

So when using

With ActiveDocument.Tables(1).Cell(1, 2).Shading
.BackgroundPatternColor = wdBlue
End With

you get a color that isn't absolutely black, but almost black,
exactly it is RGB(2, 0, 0).

Try, e.g.
..BackgroundPatternColor = wdColorBlue

However, I don't understand what could be wrong with:

With ActiveDocument.Tables(1).Cell(1, 2).Shading
.BackgroundPatternColorIndex = wdBlue
End With

Works perfectly, here and now.

Greetings from Bavaria, Germany

Helmut Weber, MVP
"red.sys" & chr(64) & "t-online.de"
Word XP, Win 98
http://word.mvps.org/
 
J

Jim Boyce

Helmut, thanks for the reply. No matter what value I use, the cell is always
black. Here is the code:

Word.ActiveDocument.Tables(tblIndex).Cell(cellStart,
2).Shading.BackgroundPatternColor = wdColorBlue

I've tried the grays, colors, etc., all with the same effect.

Jim
 
H

Helmut Weber

Hi Jim,
one more example. Put the cursor in a cell in a Word document,
and step through the following in single step mode in Word-(!)-VBA.

Sub test09887()
Selection.Collapse
Selection.Cells(1).Shading.BackgroundPatternColor = wdColorBlue
ActiveDocument.Undo 1
Selection.Collapse
Selection.Cells(1).Shading.BackgroundPatternColorIndex = wdBlue
ActiveDocument.Undo 1
Selection.Collapse

Though, if you are approaching Word form another application,
and don't use early binding and don't use option explicit
or something similar in the calling application, then whatever
color (or unknown variable you choose), Word will always treat
it as 0 (zero), which is black.

Greetings from Bavaria, Germany

Helmut Weber, MVP
"red.sys" & chr(64) & "t-online.de"
Word XP, Win 98
http://word.mvps.org/
 
C

Cindy M -WordMVP-

Hi Jim,
No matter what value I use, the cell is always
black. Here is the code:

Word.ActiveDocument.Tables(tblIndex).Cell(cellStart,
2).Shading.BackgroundPatternColor = wdColorBlue

I've tried the grays, colors, etc., all with the same effect.
Version of Word? Does your printer support color printing? Or
is it set to print only black-and-white? Are you able to color
shade cells in tables when NOT using VBA?

Cindy Meister
INTER-Solutions, Switzerland
http://homepage.swissonline.ch/cindymeister (last update Jun 8
2004)
http://www.word.mvps.org

This reply is posted in the Newsgroup; please post any follow
question or reply in the newsgroup and not by e-mail :)
 
J

Jim Boyce

That was it. I was automating Word from Outlook. When I enter a value rather
than use a constant, it works as expected. Thanks for the help!

Jim
 

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