Solved

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

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

It is often necessary in this forum and others to illustrate Word fields as text with the field delimiters replaced with the curly brackets that the delimiters resemble when field codes are being displayed on the document. This means that the text c…
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 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…
This Micro Tutorial well show you how to find and replace special characters in Microsoft Word. This is similar to carriage returns to convert columns of values from Microsoft Excel into comma separated lists.

863 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

27 Experts available now in Live!

Get 1:1 Help Now