?
Solved

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

Posted on 2015-01-27
4
Medium Priority
?
110 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 36

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 52

Accepted Solution

by:
Rgonzo1971 earned 2000 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

New benefit for Premium Members - Upgrade now!

Ready to get started with anonymous questions today? It's easy! Learn more.

Question has a verified solution.

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

The Selection object is designed for user interaction. It has a Range property, so it can be used in most places that a Range object can. Recorded macros must use the Selection because they are simply copying what the user is doing. A Range prope…
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…
This video walks the viewer through the process of creating an MLA formatted document, as well as a bibliography with citations.
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…
Suggested Courses
Course of the Month8 days, 14 hours left to enroll

765 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