Microsoft Office Forums

Go Back   Microsoft Office Forums > >

 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
  #9  
Old 08-21-2016, 11:27 AM
gmaxey gmaxey is offline Macro to return a word count of text contained within a bookmark Windows 7 32bit Macro to return a word count of text contained within a bookmark Office 2010 (Version 14.0)
Expert
 
Join Date: May 2010
Location: Brasstown, NC
Posts: 1,635
gmaxey is just really nicegmaxey is just really nicegmaxey is just really nicegmaxey is just really nicegmaxey is just really nice
Default

I suppose that a part of the point of my code is that "bookmarks" are redundant and not necessary in your example document format. A bookmark is just a defined range. Well a table cell is also a defined range so you can use one or the other.

Code:
Sub ScratchMacro()
'A basic Word macro coded by Greg Maxey
Dim oTbl As Word.Table
Dim lngTable As Long
Dim lngIndex As Long, lngRow As Long, lngCount As Long
Dim arrCounts() As String
Dim oRng As Range
Dim oDoc As Document
  ReDim arrCounts(1 To ActiveDocument.Tables.Count, 1 To 2)
  For lngTable = 1 To ActiveDocument.Tables.Count
    Set oTbl = ActiveDocument.Tables(lngTable)
    For lngRow = 2 To oTbl.Rows.Count
      If lngRow = 2 Then
        Set oRng = oTbl.Cell(lngRow, 1).Range
        oRng.End = oRng.End - 1
        arrCounts(lngTable, 1) = oRng.Text
      End If
      Set oRng = oTbl.Cell(lngRow, oTbl.Columns.Count).Range
      oRng.End = oRng.End - 1
      arrCounts(lngTable, 2) = oRng.ComputeStatistics(wdStatisticWords)
    Next lngRow
  Next lngTable
lbl_Exit:
  Set oDoc = Documents.Add
  Set oTbl = oDoc.Tables.Add(oDoc.Range, UBound(arrCounts), 2)
  For lngIndex = 1 To UBound(arrCounts)
    oTbl.Cell(lngIndex, 1).Range.Text = arrCounts(lngIndex, 1)
    oTbl.Cell(lngIndex, 2).Range.Text = arrCounts(lngIndex, 2)
  Next
  Exit Sub
End Sub
__________________
Greg Maxey
Please visit my web site at http://www.gregmaxey.com/
Reply With Quote
 

Tags
word count macro



Similar Threads
Thread Thread Starter Forum Replies Last Post
Macro to return a word count of text contained within a bookmark FORMTEXT field contained in INCLUDETEXT bookmark emwinschuh Word 1 08-17-2015 08:55 AM
Macro to return a word count of text contained within a bookmark A recurring word count macro? bpanda Word VBA 1 06-11-2013 07:17 AM
Macro to return a word count of text contained within a bookmark Word Count Macro bpanda Word VBA 1 01-11-2013 06:51 PM
Macro to return a word count of text contained within a bookmark Word 2003 - IncludeText Does Not Include Bookmark Text if in a Form Text Control skarden Word 1 12-12-2011 10:39 PM
*Word 2007 Macro for Character Count gbartlet Word 0 07-21-2010 11:12 AM

Other Forums: Access Forums

All times are GMT -7. The time now is 08:16 AM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2025, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2025 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft