Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.word.newusers
|
|||
|
|||
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
Posted to microsoft.public.word.newusers
|
|||
|
|||
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
Posted to microsoft.public.word.newusers
|
|||
|
|||
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
Posted to microsoft.public.word.newusers
|
|||
|
|||
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 | |
|
|
Similar Threads | ||||
Thread | Forum | |||
Help Creating a Macro Automating an Envelope Template Using Word 2 | Page Layout | |||
Macro for word tables to excel | Tables | |||
Creating a macro | Page Layout | |||
creating a macro | New Users | |||
Windows XP MS Word, need interactive/live demo, creating a Macro | New Users |