Solved

Apply a paragraph style to cells in certain tables using a macro

Posted on 2015-01-27
4
103 Views
Last Modified: 2015-01-27
Dear Experts:

I would like to run a macro with the following requirements:

In the current document the macro is to run thru all the tables and check whether there are tables where ...

... Cell(Row:=2,Column:=1) features the 'Normal' paragraph style

Those tables that fulfill this requirement have to be formatted as follows:

Cells(Row:=2, Column:=4) to Cells(Row:=x, Column:=5) have to be applied a custom made paragraph style 'MyParagraphStyle'

Help is much appreciated.

Thank you very much in advance.

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

Expert Comment

by:Kimputer
ID: 40572869
When you have the correct cells in a range, use:

.Style = ActiveDocument.Styles("MyParagraphStyle")

Open in new window

0
 
LVL 49

Accepted Solution

by:
Rgonzo1971 earned 500 total points
ID: 40572908
Hi,

pls try

Sub Macro()
   With ActiveDocument
   Set a = ActiveDocument.Tables
        For Idx = 1 To .Tables.Count
            Set rng = .Tables(Idx).Cell(2, 1).Range
            If rng.Paragraphs(1).Style.NameLocal = "Normal" Then ' MyTableStyle
                For IdxCl = 4 To 5
                    For IdxRw = 2 To .Tables(Idx).Rows.Count
                         .Tables(Idx).Cell(IdxRw, IdxCl).Range.Style = ActiveDocument.Styles("Subtitle")
                    Next
                Next
            End If
        Next
    End With
    
End Sub

Open in new window

Regards
0
 

Author Comment

by:AndreasHermle
ID: 40572918
Hi Kimputer,

thank you very much for your swift help. I am afraid to tell you that I am not able to write a macro code, so your code snippet is regrettably of no use to me.

I can understand code quite good but am not able to write a full macro.

Regards, Andreas
0
 

Author Closing Comment

by:AndreasHermle
ID: 40572957
You impressed me again! Great job. Thank you very much for your swift and professional help. Really very helpful

Regards, Andreas
0

Featured Post

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

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

If you work with Word a lot, you probably use styles. If you use styles a lot, you've probably balled your fist more often than not when working with the ribbon. In Word 2007/2010, one of the things that I find missing when using styles is a quic…
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 video shows and describes the main difference between both orientations in Microsoft Word. Viewers will understand when to use each orientation and how to get the most out of them.
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 …

832 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