Find PaleBlue and Replace with Yellow in all Tables

M

Mark

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
 
J

JBNewsGroup

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
 
J

JBNewsGroup

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
 
M

Mark

Many thanks

I'll give it a shot

Mark

JBNewsGroup said:
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
 
M

Mark

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
 
J

JBNewsGroup

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
 

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