View Single Post
 
Old 03-25-2016, 03:43 PM
macropod's Avatar
macropod macropod is offline Windows 7 64bit Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 22,341
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

Sure one could, but that isn't what you had asked for. All you asked for originally was how to get the counts. I gave you a simple macro for that because I had no idea what you wanted to do with them after they were generated. For all I knew, you wanted to read & delete them or attach them to your actual headings.

I still don't see the point in generating this kind of stuff with a macro when you can get the word count for any range you're interested in just by selecting the range and looking at the word count stats on the status bar. That said, try:
Code:
Sub Demo()
Dim Sctn As Section, StrCounts As String, Rng As Range, TOC As TableOfContents
With ActiveDocument
  For Each Sctn In .Sections
    StrCounts = StrCounts & "Section " & Sctn.Index & ":" & vbTab & _
      Sctn.Range.ComputeStatistics(wdStatisticWords) & vbCr
  Next
  Set Rng = .Characters.Last
  With Rng
    .InsertAfter StrCounts
    .End = .End - 1
    .Style = wdStyleHeading2
  End With
  For Each TOC In .TablesOfContents
    TOC.Update
  Next
End With
End Sub
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote