View Single Post
 
Old 06-11-2013, 07:17 AM
gmaxey gmaxey is offline Windows 7 32bit Office 2010 (Version 14.0)
Expert
 
Join Date: May 2010
Location: Brasstown, NC
Posts: 1,601
gmaxey is just really nicegmaxey is just really nicegmaxey is just really nicegmaxey is just really nicegmaxey is just really nice
Default

Code:
Sub SectionWordCount()
Dim lngIndex As Long
Dim oRng As Word.Range
Dim strBMName As String
Dim strCount As String
  With ActiveDocument
    For lngIndex = 1 To .Sections.Count
      strCount = "(" + Format(.Sections(lngIndex).Range.ComputeStatistics(wdStatisticWords)) + " words)"
      strBMName = "WordCount" & "_" & lngIndex
      On Error Resume Next
      Set oRng = .Bookmarks(strBMName).Range
      If Err.Number <> 0 Then
        Set oRng = .Sections(lngIndex).Range
        oRng.Collapse wdCollapseEnd
        If Asc(oRng.Characters(1).Previous) = 12 Then
          oRng.Move wdCharacter, -1
        End If
      Else
        oRng.Delete
      End If
      oRng.Text = vbCr & strCount
      oRng.MoveStart wdCharacter, 1
      .Bookmarks.Add Name:=strBMName, Range:=oRng
    Next
  End With
lbl_Exit:
  Exit Sub
End Sub
__________________
Greg Maxey
Please visit my web site at http://www.gregmaxey.com/
Reply With Quote