Solved

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

Posted on 2015-01-27
4
100 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 48

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

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

Suggested Solutions

Nice table. Huge mess. Maybe this was something you created way back before you figured out tabs or a document you received from someone else. Either way, using the spacebar to separate the columns resulted in a mess. Trying to convert text to t…
This is written from a 'VBA for MS Word' perspective, but I am sure it applies to most other MS Office components where VBA is used.  One thing that really bugs me is slow code, ESPECIALLY when it's mine!  In programming there are so many ways to…
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.
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 …

762 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now