Table - counting words

J

John Smith

I pasted a two column table from Excel to Word. The left column contains
words while the right column is empty. How do I count words in the left
column and store the results to the right column?

Also, how do I select a single column (in its entirety)? Thanks.
 
S

StevenM

To: John Smith,

'
' CountWords
' counts words in the first column of the first table
' and places the count in the second column
'
Sub CountWords()
Dim oRow As Row
For Each oRow In ActiveDocument.Tables(1).rows
oRow.Cells(2).Range.Delete
oRow.Cells(2).Range.Text = oRow.Cells(1).Range.Words.count - 1
Next oRow
End Sub

Steven Craig Miller
 
S

StevenM

Part 2:

Sub SelectColumn()
ActiveDocument.Tables(1).Columns(1).Select
End Sub

The above selects the first column of the first table in the active document.

Steven Craig Miller
 
J

John Smith

Thank you. The codes work fine except for 2-byte languages. Anyway to
get a correct count for 2-byte languages?

StevenM æ到:
 
S

StevenM

To: John Smith,

I don't know anything about 2-byte languages, but if the number is exactly
twice what is needed, then:

'
' CountWordsBy2
' counts words in the first column of the first table
' and places the count (divided by 2) in the second column
' "\" is the integer division operator as opposed to
' "/" which is the floating-point division operator.
'
Sub CountWordsBy2()
Dim oRow As Row
For Each oRow In ActiveDocument.Tables(1).rows
oRow.Cells(2).Range.Delete
oRow.Cells(2).Range.Text = (oRow.Cells(1).Range.Words.count - 1) \ 2
Next oRow
End Sub

But if that is not the problem, perhaps you could explain.

Steven Craig Miller
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top