tables using visual basic

D

dhickey

I have a document and it has multiple tables with shading. The shadin
ranges from 20-35 percent. I am using WORD97. How can I do
edit/replace in VB to find all the shading and replace it with 10%.

Please help

Debbi
 
K

Klaus Linke

I have a document and it has multiple tables with shading.
The shading ranges from 20-35 percent. I am using WORD97.
How can I do a edit/replace in VB to find all the shading and
replace it with 10%.


Hi Debbie,

Edit > Replace doesn't work for this.
You'd loop through all cells in all tables, and set the shading to 10% if
it is currently 20-35 percent.

If you want to apply 10% shading to all cells that currently have any
shading at all (other than "automatic" = none):

Dim myTable As Table
Dim myCell As Cell
For Each myTable In ActiveDocument.Tables
For Each myCell In myTable.Range.Cells
With myCell.Shading
If .BackgroundPatternColor <> _
wdColorAutomatic Then
.BackgroundPatternColor = wdColorGray10
End If
End With
Next myCell
Next myTable

I'm not sure if Word97 used RGB colors, or if it used textures. If the
latter, you would write something like
If .Texture <> wdTextureNone Then
.Texture = wdTexture10Percent
End If
in the inner loop.

Regards,
Klaus
 
D

dhickey

Klaus that visual basic code worked for my tables except for when the
shading is using a pattern style instead of a fill. What would I add
to the code.

Debbie
 
K

Klaus Linke

dhickey > said:
Klaus that visual basic code worked for my tables except for when
the shading is using a pattern style instead of a fill. What would I add
to the code.

Debbie


Hi Debbie,

If you want to replace any pattern with 10% gray shading, the macro below
should hopefully work.
If you only want to replace the shading in some tables, select them and
replace "ActiveDocument.Tables" with "Selection.Tables" in the macro.

Regards,
Klaus

Dim myTable As Table
Dim myCell As Cell
For Each myTable In ActiveDocument.Tables
For Each myCell In myTable.Range.Cells
With myCell.Shading
If .Texture <> wdTextureNone Then
.Texture = wdTextureNone
.BackgroundPatternColor = wdColorGray10
End If
End With
Next myCell
Next myTable

Regards,
Klaus
 
D

dhickey

What is happening is on the new code you sent me that works if it has
pattern but it does not work on the fill. The first one you gave m
worked on the fill. It does not work for both. Any ideas
 

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