Avatar of vinod Kumar
vinod Kumar
Flag for India

asked on 

Count of different word styles as csv file

I need count of different word styles in the word document as a CSV file with column headers Style name and Styles Count.

My VB code for output as a popup for particular style in the word document.

   
Sub Count()
    Dim l As Long
    ResetSearch
    With ActiveDocument.Range.Find
       .Style = "Strong" 'Replace with the name of the style you are counting
       While .Execute
          l = l + 1
          If l > ActiveDocument.Range.Paragraphs.Count Then
             Stop
          End If
       Wend
    End With
    MsgBox l
    ResetSearch
    End Sub
    
    Public Sub ResetSearch()
    With Selection.Find
       .ClearFormatting
       .Replacement.ClearFormatting
       .Text = ""
       .Replacement.Text = ""
       .Forward = True
       .Wrap = wdFindContinue
       .Format = False
       .MatchCase = False
       .MatchWholeWord = False
       .MatchWildcards = False
       .MatchSoundsLike = False
       .MatchAllWordForms = False
       ' plus some more if needed
       .Execute
    End With
    End Sub

Open in new window


Please suggest that different styles in word not only strong any type of style count in csv format column headers are Style name and Styles Count
VB ScriptVBAMicrosoft Word

Avatar of undefined
Last Comment
vinod Kumar

8/22/2022 - Mon