none
Problem with MS Word macro to count strikethrough text in a selected Section RRS feed

  • Question

  • I've created a macro that counts the number of words in "strikethrough" in a given section.  However, it does not stop with the current section ... it counts strikethrough text from the current section and all sections forward.  I want it to count only the section in which the cursor is placed.

    What am I doing wrong?  Here is the macro:

    ---------------------

    Sub CountStrikethrough()

    Dim rngWords As Range
    Set rngWords = ActiveDocument.Range.Sections(Selection.Information(wdActiveEndSectionNumber)).Range

    Dim strikethroughCount As Long

    Do
    With rngWords.Find
        .Font.StrikeThrough = True
            .Forward = True
        .Execute
        If rngWords.Find.Found = True Then
            strikethroughCount = strikethroughCount + rngWords.ComputeStatistics(wdStatisticWords)
        Else
            Exit Do
        End If
    End With
    Loop
    MsgBox "Section " & Selection.Information(wdActiveEndSectionNumber) _
        & " has " & strikethroughCount & " words w/strikethrough"
    End Sub
    Tuesday, December 1, 2015 2:45 AM