Creating a macro for Tables in Word 97

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

How can I create a macro that will apply shading to alternate rows in a
table? I work with some very long tables that span several pages in a
document. Rather than selecting alternate rows individually and applying
shading, it would be a great time-saver to create a macro that will apply
shading to alternate rows. Thanks in advanced.
 
Outlook said:
How can I create a macro that will apply shading to alternate rows in
a table? I work with some very long tables that span several pages
in a document. Rather than selecting alternate rows individually and
applying shading, it would be a great time-saver to create a macro
that will apply shading to alternate rows. Thanks in advanced.

Try this (read http://www.gmayor.com/installing_macro.htm if needed):

Sub ShadeAlternateRows()
Dim oTbl As Table
Dim nRow As Long

If Selection.Information(wdWithInTable) Then
Set oTbl = Selection.Tables(1)
For nRow = 1 To oTbl.Rows.Count Step 2
oTbl.Rows(nRow).Shading.BackgroundPatternColor _
= wdColorGray10
Next
End If
End Sub

You can change the color (wdGray10 is 10% gray) to any other color
constant -- to see the list in the VBA editor, choose View > Object Browser,
enter wdColor in the search box, and press Enter.
 
Jay -

Thanks for the instructions - it worked out great! It took me a few minutes
to figure out that I need to click on the "View Code" button in order to copy
and paste your code, but I finally figured it out. Is there a way to assign
this macro to an icon? Thanks again! You made my life a whole lot easier :)
 
Back
Top