What vba code is used in Access 2007 to back shade Word 2007 table cells?


I am using the following code to store data into a Word table from Access 2007:
with doc
'Header cells
.Tables(2).Cell(1, 1).Range.Text="Total"
.Tables(2).Cell(1, 2).Range.Text="%Compliant"
end with

do while ....
Set rw = doc.Tables(2).Rows.Add
With rw
'Text cells
.Cells(1).Range.Text = me.total
.Cells(2).Range.Text = me.Compliant
end with
loop

How can I back shade the cells of the headers cells, but not back shade the cells of the text cells?
newbie46Asked:
Who is Participating?
 
andrewssd3Commented:
OK crossed over with your comment - that's White text, and to get bold you say
With .Tables(2).Cell(1, 1)
    .Range.Text = "Total"
    .Shading.ForegroundPatternColor = wdColorGray15 ' or whatever
    .Range.Font.Color = wdColorWhite
    .Range.Font.Bold = True
End With

Open in new window

0
 
andrewssd3Commented:
You want to use something like this for the hearder cells code:
With .Tables(2).Cell(1, 1)
    .Range.Text = "Total"
    .Shading.ForegroundPatternColor = wdColorGray15
End With
With .Tables(2).Cell(1, 2)
    .Range.Text = "Total"
    .Shading.ForegroundPatternColor = wdColorGray15
End With

Open in new window

Obviously this makes the background colur grey, but you should get a list through intellisense of the available colours when you type in the statements.
0
 
andrewssd3Commented:
Sorry - obviously Line 6 should have your original text:
    .Range.Text ="%Compliant"

Open in new window

0
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

 
newbie46Author Commented:
andrewssd3,
Thanks. Now, how do I set the color to none for the text? I don't see a choice of wdNone.
0
 
newbie46Author Commented:
andrewssd3,
My goal is to create the document that is attached.
Doc1.docx
0
 
andrewssd3Commented:
What do you mean by none?  You could try wdColorAutomatic, or wdColorWhite.  If you want the text to be invisble, set it to the same colour you gave to the background. You should be using this basic code:
    .Range.Font.Color = wdColorAutomatic

Open in new window

Inside the With block for each cell.
0
 
newbie46Author Commented:
andrewssd3,
This works perfect! What about the additional question that I had posted within the Word doc (below):

Access VBA is appending rows to the table’s columns 1 – 9. If I create 2 tables, one containing the header info above and one containing the appended rows of data, the lines don’t match up and there is a gap between the tables. Is there a way to append the header rows to the Word doc within Access, and still be able to append the data to line up as shown in the Word doc?  

In other words, through VBA, can you control the lines being drawn and control how many cells are used for text? For example, ‘Passed’ spans 2 cells and I don’t want to see the line drawn between the 2 cells in this case.

thanks.
0
 
andrewssd3Commented:
Hi - as this is a different question, you should really close this one off and post a new question so that other people can take a look at it for you and so that people in the future looking for solutions will be able to find it more easily. Especially since what you're asking is not very simple!
0
 
newbie46Author Commented:
Will do. Thank you very much!!
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.