Avatar of rexswain
rexswain asked on

VBA code to select several cells of a Word table

I am new to the Word document object model, so forgive me if this is easy.  

I want to change the background color of several cells in a Word table.  I know how to iterate through the cells setting

 Cell(r,c).Shading.BackgroundPatternColor

on each cell.  But this is kinda slow, and I assume it would be faster for me to select a contiguous range of cells and set Shading on them all at once.  The cells are not an entire row or column.  I'm thinking I should be able to use Cells and/or Range to do this, but I have not been able to hit on a solution.

(If it makes a difference, I'm actually talking to a Word table embedded in a PowerPoint slide.)
Microsoft Word

Avatar of undefined
Last Comment
rexswain

8/22/2022 - Mon
GrahamSkan

You can do a row or a column at a time.

doc.Tables(1).Columns(1).Shading.BackgroundPatternColor = wdColorBrightGreen
GrahamSkan

Sorry, just seen that you specifically don't want a row or a column.
ASKER CERTIFIED SOLUTION
GrahamSkan

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
See how we're fighting big data
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question
ASKER
rexswain

Thanks.  And it is indeed much faster that iterating through each individual cell.
This is the best money I have ever spent. I cannot not tell you how many times these folks have saved my bacon. I learn so much from the contributors.
rwheeler23