Link to home
Start Free TrialLog in
Avatar of Andreas Hermle
Andreas HermleFlag for Germany

asked on

Apply a user-defined paragraph style to the first paragraph of Cell (1,1) of all the tables of the current document

Dear Experts:

below macro (Courtesy of MS Word 'Sage' Graham Skan) applies a user-defined paragraph style to the table cell that is located on the intersection of Row 4 and Column 2 (see line 10).

Could somebody please tweak this code due to a new requirement. The requirement is as follows:

Apply the heading Style "MyParaStyle" to the first paragraph of table cell (1,1), i.e. table cell (1,1) contains several paragraphs and only the first one should get the user-defined paragraph style applied.

Help is much appreciated. Thank you very much in advance.

Regards, Andreas



Sub ApplyStyle()
    Dim tbl As Table
    
     If MsgBox("Would you like to apply the 'MyParaStyle' to the item name?" & vbCrLf & vbCrLf & _
     "This will be the basis for the Adobe Acrobat bookmarks!", vbQuestion + vbYesNo, "Apply Style to Product Name") = vbNo Then
        Exit Sub
        End If
    
    For Each tbl In ActiveDocument.Tables
        tbl.Cell(4, 2).Range.Style = "MyParaStyle"
    Next tbl
End Sub

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of Norie
Norie

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Andreas Hermle

ASKER

Hi Norie, great this did the trick. Thank you very much for it.

Regards, Andreas