Reply
 
Thread Tools Display Modes
  #1   Report Post  
Posted to microsoft.public.word.newusers
Outlook Convert Outlook Convert is offline
external usenet poster
 
Posts: 5
Default Creating a macro for Tables in Word 97

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.
  #2   Report Post  
Posted to microsoft.public.word.newusers
Jay Freedman Jay Freedman is offline
external usenet poster
 
Posts: 9,854
Default Creating a macro for Tables in Word 97

Outlook Convert wrote:
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.


  #3   Report Post  
Posted to microsoft.public.word.newusers
Outlook Convert Outlook Convert is offline
external usenet poster
 
Posts: 5
Default Creating a macro for Tables in Word 97

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

"Jay Freedman" wrote:

Outlook Convert wrote:
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.



  #4   Report Post  
Posted to microsoft.public.word.newusers
Jay Freedman Jay Freedman is offline
external usenet poster
 
Posts: 9,854
Default Creating a macro for Tables in Word 97

Yes, you can make a button. Read
http://www.word.mvps.org/FAQs/Custom...oToToolbar.htm for
instructions.

--
Regards,
Jay Freedman
Microsoft Word MVP FAQ: http://word.mvps.org
Email cannot be acknowledged; please post all follow-ups to the newsgroup so
all may benefit.


Outlook Convert wrote:
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

"Jay Freedman" wrote:

Outlook Convert wrote:
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.



Reply
Thread Tools
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Help Creating a Macro Automating an Envelope Template Using Word 2 Ytestt Page Layout 4 November 24th 06 05:53 AM
Macro for word tables to excel [email protected] Tables 1 July 12th 06 11:21 PM
Creating a macro dk Page Layout 10 November 17th 05 04:36 PM
creating a macro MTlyn New Users 2 November 10th 05 09:36 PM
Windows XP MS Word, need interactive/live demo, creating a Macro Mitchina New Users 5 February 4th 05 05:57 PM


All times are GMT +1. The time now is 11:12 AM.

Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 Microsoft Office Word Forum - WordBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Word"