Link to home
Start Free TrialLog in
Avatar of newbie46
newbie46

asked on

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?
Avatar of andrewssd3
andrewssd3
Flag of United Kingdom of Great Britain and Northern Ireland image

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.
Sorry - obviously Line 6 should have your original text:
    .Range.Text ="%Compliant"

Open in new window

Avatar of newbie46
newbie46

ASKER

andrewssd3,
Thanks. Now, how do I set the color to none for the text? I don't see a choice of wdNone.
andrewssd3,
My goal is to create the document that is attached.
Doc1.docx
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.
ASKER CERTIFIED SOLUTION
Avatar of andrewssd3
andrewssd3
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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.
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!
Will do. Thank you very much!!