Find a style and then run a macro

M

Macro''er :)

Hello,

Please help! I am looking for a script to Find all Style[Heading 1] within
the active document and once the style is found, run a macro that exist. The
existing macro is to format the table where heading 1 is applied.

Hope this makes sense.

Thank you for your help as always!!! :)
 
P

Pesach Shelnitz

Hi,

The following macro finds all instances of the Heading 1 style. Each time
that it finds text formatted with this style, it moves the insertion point to
the end of the selection formatted with the Heading 1 style and calls a macro
called DoSomething (included), which displays a message. You can replace the
name DoSomething with the name of your macro.

Sub FindHeading1()

Selection.HomeKey wdStory
With Selection.Find
.ClearFormatting
.Style = ActiveDocument.Styles(wdStyleHeading1)
.Text = ""
.Forward = True
.Wrap = wdFindStop
.Format = True
Do While .Execute = True
Selection.Collapse Direction:=wdCollapseEnd
Call DoSomething
Loop
End With
End Sub

Private Sub DoSomething()
MsgBox "Heading 1 found"
End Sub
 
M

Macro''''er

This is exactly what I'm looking for. Thank you so very much!!

Have a great day!!!
--
Smile...it is good for you! :)


Pesach Shelnitz said:
Hi,

The following macro finds all instances of the Heading 1 style. Each time
that it finds text formatted with this style, it moves the insertion point to
the end of the selection formatted with the Heading 1 style and calls a macro
called DoSomething (included), which displays a message. You can replace the
name DoSomething with the name of your macro.

Sub FindHeading1()

Selection.HomeKey wdStory
With Selection.Find
.ClearFormatting
.Style = ActiveDocument.Styles(wdStyleHeading1)
.Text = ""
.Forward = True
.Wrap = wdFindStop
.Format = True
Do While .Execute = True
Selection.Collapse Direction:=wdCollapseEnd
Call DoSomething
Loop
End With
End Sub

Private Sub DoSomething()
MsgBox "Heading 1 found"
End Sub

--
Hope this helps,
Pesach Shelnitz


Macro''er :) said:
Hello,

Please help! I am looking for a script to Find all Style[Heading 1] within
the active document and once the style is found, run a macro that exist. The
existing macro is to format the table where heading 1 is applied.

Hope this makes sense.

Thank you for your help as always!!! :)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top