View Single Post
 
Old 10-17-2019, 03:09 AM
mobj mobj is offline Windows 10 Office 2019
Novice
 
Join Date: Oct 2019
Posts: 2
mobj is on a distinguished road
Default

Quote:
Originally Posted by gmaxey View Post
Code:
Sub ScratchMacro()
'A basic Word macro coded by Greg Maxey
Dim lngCount
Dim oCell As Cell
Dim oRng As Range
  For Each oCell In Selection.Tables(1).Range.Cells
    If oCell.Range.Information(wdEndOfRangeColumnNumber) = 2 Then 'or whatever column index you need
      If oCell.Shading.BackgroundPatternColor = wdColorAutomatic Then
        Set oRng = oCell.Range
        oRng.End = oRng.End - 1
        lngCount = lngCount + oRng.ComputeStatistics(wdStatisticWords)
      End If
    End If
  Next
  MsgBox lngCount
lbl_Exit:
  Exit Sub
End Sub

Wow, thank you so much! Works like a charm - I simply chose the right column number, and now click on the table, shortcut key the macro, and type the word count into an excel spreadsheet. What used to take me almost 1 minute per document now takes 5 seconds. Thank you!!
Reply With Quote