View Single Post
 
Old 08-21-2016, 11:27 AM
gmaxey gmaxey is offline Windows 7 32bit Office 2010 (Version 14.0)
Expert
 
Join Date: May 2010
Location: Brasstown, NC
Posts: 1,617
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