Joshua Martinez
asked on
Creating a "Do Loop" that ends at the last "Heading 2" style of a document
I'm working on a macro that inserts a style separator before the first period in every heading level 2 paragraph. It is also set up to skip any paragraph that is not heading 2. Currently it only works as many times as you specifically trigger it, but I would like it to continue looping until the last style separator is inserted in the last heading 2 paragraph. I can't figure out how to loop this without creating an infinite loop. I'm new to the macro writing game so please excuse my code:
I'm not sure what sort of condition I would need to set for the Do Loop for it to end after the last heading level 2 paragraph is found.
If Selection.Style = "Heading 2" Then
Selection.MoveUntil Cset:=".", Count:=100
Application.Run MacroName:="LWmacros.basHNum.InsertStyleSeparator"
ActiveWindow.Selection.GoTo wdGoToHeading, wdGoToNext
ElseIf Selection.Style <> "Heading 2" Then
ActiveWindow.Selection.GoTo wdGoToHeading, wdGoToNext
End If
I'm not sure what sort of condition I would need to set for the Do Loop for it to end after the last heading level 2 paragraph is found.
Please post your InsertStyleSeparator macro code.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
If that was not your intention, perhaps you should explain what you are trying to do with the macro, regardless of how to code it.
ASKER
This worked perfectly! All I needed to do was replace the "selection.InsertStyleSepa rator" with our in-house style separator macro we created. You are a life saver, truly.
ASKER
I couldn't be any happier with this solution.