I have a Word 2003 document with a number of tables that have certain cells
with a pale blue background. I wish to change the background colour of these
cells to Yellow. I thought I could do it with find and replace, but have had
no success.
I'm wondering if someone could help with a macro to achieve this.
Mark
JBNewsGroup - 11 Mar 2005 06:51 GMT
Hi Mark,
Try this macro. I tested it with Word2000 but it should work with Word2003.
Since you did not specify, I assumed that the tables have no Merged Rows
and/or Columns.
Dim oTable as Table
Dim oRow as Row
Dim oCell as Cell
For Each oTable in ActiveDocument.Tables
For Each oRow in oTable.Rows
For Each oCell in oRow.Cells
If (oCell.Shading.BackgroundPatternColor =
wdColorPaleBlue) Then
oCell.Shading.BackgroundPatternColor = wdColorYellow
End If
Next oCell
Next oRow
Next oTable
Jerry Bodoff
> I have a Word 2003 document with a number of tables that have certain cells
> with a pale blue background. I wish to change the background colour of these
[quoted text clipped - 4 lines]
>
> Mark
JBNewsGroup - 11 Mar 2005 07:11 GMT
Hi Mark,
Ignore my previous Macro. The following is a little simpler and should work
with merged rows and columns.
Dim oTable As Table
Dim oCell As Cell
For Each oTable In ActiveDocument.Tables
For Each oCell In oTable.Range.Cells
If (oCell..Shading.BackgroundPatternColor = wdColorPaleBlue)
Then
oCell..Shading.BackgroundPatternColor = wdColorYellow
End If
Next oCell
Next oTable
Jerry Bodoff
> I have a Word 2003 document with a number of tables that have certain cells
> with a pale blue background. I wish to change the background colour of these
[quoted text clipped - 4 lines]
>
> Mark
Mark - 11 Mar 2005 07:54 GMT
Many thanks
I'll give it a shot
Mark
> Hi Mark,
>
[quoted text clipped - 27 lines]
>>
>> Mark
JBNewsGroup - 11 Mar 2005 13:55 GMT
Hi Mark,
Let me know if you have any problems
Jerry B
> Many thanks
>
[quoted text clipped - 33 lines]
> >>
> >> Mark
Mark - 11 Mar 2005 22:38 GMT
Many thanks. Yes it worked fine. My final macro was:
Sub Find_Blue_Rep_Yellow()
' Find PaleBlue replace with Yellow
Dim oTable As Table
Dim oCell As Cell
For Each oTable In ActiveDocument.Tables
For Each oCell In oTable.Range.Cells
If oCell.Shading.BackgroundPatternColor = wdColorPaleBlue Then
oCell.Shading.BackgroundPatternColor = wdColorYellow
End If
Next oCell
Next oTable
End Sub
Thankyou
Mark
> Hi Mark,
>
[quoted text clipped - 40 lines]
>> >>
>> >> Mark
JBNewsGroup - 11 Mar 2005 23:03 GMT
Hi Mark,
You are welcome. I thought of something else that might occur if the tables
are large. The cursor may blink If that is happening and it bothers you
add:
Application.ScreenUpdating =False
before For Each oTable
and just before the End Sub add
Application.ScreenUpdating = True
In any case it would make it run faster. It doesn't hurt to leave these
statements out.
Jerry Bodoff
> Many thanks. Yes it worked fine. My final macro was:
>
[quoted text clipped - 58 lines]
> >> >>
> >> >> Mark