[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Apply a user-defined style to all paragraphs in several tables

Posted on 2012-08-14
4
Medium Priority
?
502 Views
Last Modified: 2012-08-15
Dear Experts:

I got hundreds of tables in the current document.

I would like to apply the following manual formatting properties to all paragraphs in all tables using a VBA macro:

Space before: 6 pt
Space after: 6 pt
Line spacing: 1.0

Or alternatively I would like to apply my user-defined paragraph style (MyStyle) containing all these properties to all paragraphs of all the tables in my current document.

Help is much appreciated.

Thank you very much in advance.

Regards, Andreas
0
Comment
Question by:AndreasHermle
  • 2
  • 2
4 Comments
 
LVL 59

Assisted Solution

by:Chris Bottomley
Chris Bottomley earned 2000 total points
ID: 38292854
Try:

Sub alltables()
Dim tbl As table

    For Each tbl In ActiveDocument.Tables
        With tbl.Range.ParagraphFormat
            .SpaceBefore = 6
            .SpaceAfter = 6
            .LineSpacingRule = wdLineSpaceSingle
        End With
    Next
End Sub

Open in new window


Chris
0
 

Author Comment

by:AndreasHermle
ID: 38293786
Hi Chris,

works great! Thank you very much for your great support. If I wanted to apply a custom-defined paragraph style (MyCustomStyle) to all the tables. How would the code change?

Would be great if you could provide me with this alternative as well.

Thank you so much.

Regards, Andreas
0
 
LVL 59

Accepted Solution

by:
Chris Bottomley earned 2000 total points
ID: 38293933
That would be more like:

Sub alltables2()
Dim tbl As table

    For Each tbl In ActiveDocument.Tables
        tbl.Range.Style = ActiveDocument.Styles("MyCustomStyle")
    Next
End Sub

Open in new window


Chris
0
 

Author Closing Comment

by:AndreasHermle
ID: 38295605
Hi Chris,

thank you very much for your great help. Works as desired.

Regards, Andreas
0

Featured Post

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I would like to show you some basics you can do with Mailings in MS Word. It´s quite handy feature you can use for creating envelopes, labels, personalized letters etc. First question could be what is this feature good for? Mailing can really he…
This article describes how to use the Send to Mail Recipient command. The instructions apply generally to Office 2007 and later versions, but Microsoft® Word 2013 was used for the specific steps and figures.  What is Send to Mail Recipient? Send…
This video walks the viewer through the process of creating Hyperlinks for the web and other documents. Select the "Insert" tab: Click "Hyperlink":  Type "http://" followed by a web address to reference a website or navigate to a document to ref…
Office 365 is currently available in five editions. Three of them are for business use: Office 365 Business Essentials, Office 365 Business, and Office 365 Business Premium. Two of them are for home/personal use: Office 365 Home and Office 365 Perso…
Suggested Courses

830 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