PDA

View Full Version : Tables - First Row to Always be Grey



AshZM
11-22-2021, 10:08 PM
Hi,

When I set a table to Style1, the first row is set as a Header and is grey. If I delete that first row, the second row becomes the first row, and then turns grey automatically, obviously. But, I'm wondering if this can be duplicated in VBA, or if I just have to keep running the macro whenever I want to fix the header to grey. (There are other differences in the first row like bold font, different borders, etc, but I'm simplifying it here).

I know that using VBA to set tables to Style1 will work. But, that is no fun.


So, is there any way to add code so that no matter which line in the table ends up at as the first row, it will always be grey?
This is what I already use:

Tbl.Rows.First.HeadingFormat = True
Tbl.Rows.First.Select
Selection.Shading.ForegroundPatternColor = wdColorGray05



Anyone have a magical way? I do not want to always be going in to my styles and changing Style1 when I want to change something in the header row or any other part of the table, otherwise, I'd just use Style1. I know I should just stick with a style and be happy, but VBA tables are so much fun to change.

Hopefully this makes sense.

Thanks!
-Ashley

gmayor
11-23-2021, 03:22 AM
Word comes with over 100 pre-configured table styles, all of which may be edited, or you can add your own table style to that number. It doesn't appear to make any sense to just use one style for all tables.