Changing color of word table cell using vb code

VPK_Access

Registered User.
Local time
Today, 18:23
Joined
May 15, 2011
Messages
36
Hi,

I am trying to use vb code to change the background color of a certain column in word. I have used the below code.

Set mycell = objWord.ActiveDocument.Tables(1).Cell(3, 2)
mycell.Shading.BackgroundPatternColor = wdColorLightBlue


I do not get any error. However the background color of the cell also does not change. Could anyone pleaseeeeeeeee help me.
 
You will be better off askin this question in the Word section of the forum. This section is purely for VBA for Access.

However, I tested your code in the Immediate window and it works. So perhaps the macro or event just isn't firing. To test that it is firin put a Msgbox() before the code.
 
Hi,

Thanks for the reply. Just to give a background I had used the code in the access only. I have a button in my form, clicking on which I create a word document with tables in it. I wanted a certian cell to have a color based on the value it has. I took your suggestion and included the below changes with Msgbox. It displys the Msgbox, however the background color of the cell still doesnt change. Is there a problme with the syntax?

If (rsReportData![Risk Rating] = "Red (H)") Then
MsgBox Red
objWord.ActiveDocument.Tables(1).Cell(RowCount, 7).Range.Text = rsReportData![Risk Rating]
objWord.ActiveDocument.Tables(1).Cell(RowCount, 7).Shading.BackgroundPatternColor = wdColorRed
End If
 
HI,

I have resolved the issue. I included "Microsoft 12.0 Object Library" in the reference.

And another thing I have done was that I was reading from a word template. In the word template, in the Table-> Cell-> Shading-> I made the Patter to 'Clear' value. It was previously coming as 'Solid'.

With these 2 change the color was changing.

Anyways thanks for the help.
 

Users who are viewing this thread

Back
Top Bottom