Cycle a paragraph through all available paragraph styles, eventually returning to the style the paragraph started with

Article contributed by Bill Coan

The following macro includes a line that prevents execution when text is selected. (The cursor must be flashing for the macro to run.)

I played with this a bit because someone else thought it would be a nice feature. I assigned the macro to a button, then to a keystroke. I found the keystroke much easier to use. But Word has so many built-in styles that it can be tedious to keep cycling through the styles until the original style comes back around.

Sub CycleThroughStyles()

Dim NeedToRollOver As Boolean
Dim i As Long,  j As Long, k As Long

NeedToRollOver = True

'quit if cursor isn't flashing.
'This limits action to one paragraph

If Selection.Type <> wdSelectionIP Then GoTo EndGracefully

    'find the current paragraph style, then
    'find the next available paragraph style

For i = 1 To ActiveDocument.Styles.Count
    If Selection.Paragraphs(1).Style = ActiveDocument.Styles(i) Then

        For j = i + 1 To ActiveDocument.Styles.Count
            If ActiveDocument.Styles(j).Type = wdStyleTypeParagraph Then
                Selection.Paragraphs(1).Style = ActiveDocument.Styles(j)
                NeedToRollOver = False
                Exit For
            End If
        Next j

    End If

    If NeedToRollOver = False Then
        Exit For
    End If

Next i

'if we reached the last paragraph style, then
'roll over to first available paragraph style

If NeedToRollOver = False Then GoTo EndGracefully

For k = 1 To ActiveDocument.Styles.Count
    If ActiveDocument.Styles(k).Type = wdStyleTypeParagraph Then
        Selection.Paragraphs(1).Style = ActiveDocument.Styles(k)
        Exit For
    End If
Next k

'tell user what current style is.
'clear the undo buffer to prevent error message
'about document formatting being too complex.

    Application.StatusBar = Selection.Paragraphs(1).Style

End Sub