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

Andreas HermleTeam leaderAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

NorieAnalyst Assistant Commented:
Try this.
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(1, 1).Range.Paragraphs(1).Style = "MyParaStyle"
    Next tbl
End Sub

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Andreas HermleTeam leaderAuthor Commented:
Hi Norie, great this did the trick. Thank you very much for it.

Regards, Andreas
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
VBA

From novice to tech pro — start learning today.