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

asked on

Apply built-in style heading 1 to paragraphs where the word "Speaker" occurs

Dear Experts:

I would like to have a macro that performs the following task:

As soon as the macro hits the word "Speaker", built-in style heading 1 is to applied to the paragraph where the word "Speaker" occurs.

Help is much appreciated.

Thank you very much in advance.

Regards, Andreas
ASKER CERTIFIED SOLUTION
Avatar of dlc110161
dlc110161
Flag of United States of America image

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 Chris Bottomley
Try the following:

Chris
Sub speaker()
Dim para As Long

    On Error GoTo 0
    For para = 1 To ThisDocument.Paragraphs.Count
        If InStr(1, ThisDocument.Paragraphs(para).Range.Text, "speaker", vbTextCompare) > 0 Then
            ThisDocument.Paragraphs(para).Range.Style = wdStyleHeading1
        End If
    Next
End Sub

Open in new window

SOLUTION
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

Dear all,

thank you very much for your swift help.
Although Chris' code seems logical to me, it regrettably does not work.
Dot office's code works as desired. Thank you very much
Dawn's solution is the simplest, so I guess I will award her the most points.

Again, thank you very much for your swift and great help.

Regards, Andreas
Thank you very much for your time taken and your professional help. Regards, Andreas