apply user-defined paragraph style to multiple table cells using VBA

Dear Experts:

I got a word document with hundreds of tables.

I would like to apply a custom-defined paragraph style (MyParaStyle) to a specific table cell of every table, ie. the table cell that is located in the third row of the second column of each and every table.

Help is much appreciated. Thank you very much in advance.

Regards, Andreas
Andreas HermleTeam leaderAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

GrahamSkanRetiredCommented:
Hi Andreas.
You simply need something like this:
Sub CellStyle()
    Dim tbl As Table
    
    For Each tbl In ActiveDocument.Tables
        tbl.Cell(3, 2).Range.Style = "MyParaStyle"
    Next tbl
End Sub

Open in new window

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Rgonzo1971Commented:
Hi,

pls try
Sub macro()
For Each tbl In ActiveDocument.Tables
    Set c = tbl.Cell(3, 2)
    c.Range.Style = ActiveDocument.Styles("myParaStyle")
Next
End Sub

Open in new window

Regards
Andreas HermleTeam leaderAuthor Commented:
Dear Graham,

good to hear from you again. Thank you very much for your code.

Hi Rafael, Graham was a bit quicker, therefore the majority of the points will be awarded to him.

Thank you very much anyway.

Yout two, have a nice day, I really highly appreciate your work
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
VBA

From novice to tech pro — start learning today.