A Microsoft Office (Excel, Word) forum. OfficeFrustration

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

Go Back   Home » OfficeFrustration forum » Microsoft Word » Tables
Site Map Home Register Authors List Search Today's Posts Mark Forums Read  

Adding Shaded Rows between Rows



 
 
Thread Tools Display Modes
  #1  
Old May 22nd, 2008, 06:16 PM posted to microsoft.public.word.tables
Jsec
external usenet poster
 
Posts: 2
Default Adding Shaded Rows between Rows

Can't remember how to automatically shade every other row. Can you help?
  #2  
Old May 22nd, 2008, 10:44 PM posted to microsoft.public.word.tables
Suzanne S. Barnhill
external usenet poster
 
Posts: 31,786
Default Adding Shaded Rows between Rows

There's no way to do this automatically (such that the alternation will be
preserved if you add single rows) except by applying a table style that
includes alternate row shading.

--
Suzanne S. Barnhill
Microsoft MVP (Word)
Words into Type
Fairhope, Alabama USA

"Jsec" wrote in message
news
Can't remember how to automatically shade every other row. Can you help?



  #3  
Old May 23rd, 2008, 07:16 PM posted to microsoft.public.word.tables
StevenM[_2_]
external usenet poster
 
Posts: 170
Default Adding Shaded Rows between Rows

"Jsec" wrote: Can't remember how to automatically shade every other row.
Can you help?

The following macro should help. If you need instructions on installing
macros, see: http://www.gmayor.com/installing_macro.htm

If you add new rows after running the macro, just run it again.

Sub ShadeEveryOtherRow()
Dim oTable As Table
Dim oRow As Row
Dim bClear As Boolean

On Error GoTo ErrorHandler
bClear = True
Set oTable = Selection.Tables(1)
For Each oRow In oTable.Rows
If bClear Then
oRow.Shading.BackgroundPatternColor = wdColorWhite
Else
oRow.Shading.BackgroundPatternColor = wdColorGray15
End If
If bClear = True Then
bClear = False
Else
bClear = True
End If
Next oRow

Exit Sub
ErrorHandler:
If Err.Number = 5941 Then
MsgBox "The cursor must be positioned in the table you want to
shade." _
& vbCr & vbCr & "Position the cursor and run this macro
again."
End If
End Sub



  #4  
Old May 24th, 2008, 03:20 PM posted to microsoft.public.word.tables
StevenM[_2_]
external usenet poster
 
Posts: 170
Default Adding Shaded Rows between Rows

The following is a slightly improved version of my earlier macro.

'****
'* Macro: ShadeEveryOtherRow shades every other row of a table.
'* If you add new rows to the table, just re-run this macro.
'* If you want the first row to be shaded, change "bClear = True" to False.
'* There are a number of different shades of Grey possible,
'* wdColorGray05 is very light, wdColorGray50 is very dark,
'* by increments of five, there are shades between these two.
'****
Sub ShadeEveryOtherRow()
Dim oRow As Row
Dim bClear As Boolean
If Selection.Information(wdWithInTable) = False Then
MsgBox "The cursor must be positioned in the table you want to
shade." _
& vbCr & vbCr & "Position the cursor and run this macro
again."
Else
bClear = True
For Each oRow In Selection.Tables(1).Rows
If bClear Then
oRow.Shading.BackgroundPatternColor = wdColorWhite
Else
oRow.Shading.BackgroundPatternColor = wdColorGray10
End If
bClear = Not bClear
Next oRow
End If
End Sub

 




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Forum Jump


All times are GMT +1. The time now is 11:52 PM.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 OfficeFrustration.
The comments are property of their posters.