A
andreas
Dear Experts:
with x rows of a table selected I would like to activate a macro
that ...
.... alternately shades the selected rows grey. The grey shading should
begin on the uppermost selected row.
I GOT a macro that does this alternate shading much more comfortable
(see macro below <TblAltShadingGrey>), but as soon as the macro hits
vertically merged cells, it throws an error message. Therefore I would
like to be able to apply alternate grey shading to selected rows.
I am also aware that a user-defined table style could do the above job
(alternate grey shading) very easily. But there are a couple of Word
2000 documents where I have to perform these tasks.
Help is much appreciated. Thank you very much in advance.
Regards, Andreas
Sub TblAltShadingGrey()
Dim oRow As row
Dim rng As Word.range
Dim tbl As Table
Dim StartRow As Long
Dim ShadedRow As Boolean
If Not Selection.Information(wdWithInTable) Then
MsgBox "Please place the cursor into the table", vbOKOnly +
vbCritical, "Alternate Grey Shading for selected Table"
Exit Sub
End If
StartRow = InputBox("Grey Shading: Enter starting row:", "Alternate
Grey Shading")
Set tbl = Selection.Tables(1)
Set rng = tbl.range
For Each oRow In tbl.rows
If oRow.Index >= StartRow Then
ShadedRow = Not ShadedRow
If ShadedRow Then
oRow.Cells.Shading.BackgroundPatternColor = RGB(225, 225,
225)
Else
oRow.Cells.Shading.BackgroundPatternColor =
wdColorAutomatic
End If
End If
Next
End Sub
with x rows of a table selected I would like to activate a macro
that ...
.... alternately shades the selected rows grey. The grey shading should
begin on the uppermost selected row.
I GOT a macro that does this alternate shading much more comfortable
(see macro below <TblAltShadingGrey>), but as soon as the macro hits
vertically merged cells, it throws an error message. Therefore I would
like to be able to apply alternate grey shading to selected rows.
I am also aware that a user-defined table style could do the above job
(alternate grey shading) very easily. But there are a couple of Word
2000 documents where I have to perform these tasks.
Help is much appreciated. Thank you very much in advance.
Regards, Andreas
Sub TblAltShadingGrey()
Dim oRow As row
Dim rng As Word.range
Dim tbl As Table
Dim StartRow As Long
Dim ShadedRow As Boolean
If Not Selection.Information(wdWithInTable) Then
MsgBox "Please place the cursor into the table", vbOKOnly +
vbCritical, "Alternate Grey Shading for selected Table"
Exit Sub
End If
StartRow = InputBox("Grey Shading: Enter starting row:", "Alternate
Grey Shading")
Set tbl = Selection.Tables(1)
Set rng = tbl.range
For Each oRow In tbl.rows
If oRow.Index >= StartRow Then
ShadedRow = Not ShadedRow
If ShadedRow Then
oRow.Cells.Shading.BackgroundPatternColor = RGB(225, 225,
225)
Else
oRow.Cells.Shading.BackgroundPatternColor =
wdColorAutomatic
End If
End If
Next
End Sub