Apply a user-defined style to certain cells of each and every table using VBA

Posted on 2013-09-26
Medium Priority
Last Modified: 2013-09-27
Dear Experts:

My current document has dozens of tables.

I would like ...
... to apply the user-defined style 'MyTitle' to the third cell of the second row for all tables using VBA.

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

Regards, Andreas
Question by:Andreas Hermle
LVL 37

Expert Comment

ID: 39525105
Post sample doc ?
LVL 59

Accepted Solution

Chris Bottomley earned 2000 total points
ID: 39525189
Hi Andreas.

Try for example:

Sub myStyle()
Dim tbl As Table
Dim doc As Document

    Set doc = ActiveDocument
    For Each tbl In doc.Tables
        tbl.Rows(2).Cells(3).Range.Style = doc.Styles("MyTitle")
End Sub

Open in new window

I have assumed the style exists in the document itself but you can play with that easily enough so the above will hopefuly work for the purpose on the active document


Author Closing Comment

by:Andreas Hermle
ID: 39527199
Hi Chris,

great, this did the trick. Thank you very much for your professional help.

Regards, Andreas

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Preface: When I started this series, I used the term CommandBars because that is the Office Object class that it discusses. Unfortunately, when Microsoft introduced Office 2007, they replaced the standard Commandbar menus with "The Ribbon" and rem…
Ever visit a website where you spotted a really cool looking Font, yet couldn't figure out which font family it belonged to, or how to get a copy of it for your own use? This article explains the process of doing exactly that, as well as showing how…
Learn how to make your own table of contents in Microsoft Word using paragraph styles and the automatic table of contents tool. We'll be using the paragraph styles in Word’s Home toolbar to help you create a table of contents. Type out your initial …
This Experts Exchange video Micro Tutorial shows how to tell Microsoft Office that a word is NOT spelled correctly. Microsoft Office has a built-in, main dictionary that is shared by Office apps, including Excel, Outlook, PowerPoint, and Word. When …

607 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question