Solved

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

Posted on 2015-01-27
4
107 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 51

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

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

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

Introduction Authors who set out to write any sort of lengthy piece for online submission—be it a long question or comment on a technical form, an article, or a substantial blog entry—often find it useful to work up a draft in an editor other t…
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…
The viewer will learn how to make their project stand out over others by learning how to change colors and shapes, add spaces, change directions, and add bullets to their charts.
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…

726 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