Sentence count in brackets after each period.... Can it be done?

E

e125

I would like to get Word to count each word in a given sentence, then tally
that number and place it in brackets after the period. Can Word do this with
a macro?

Any suggestions will be much appreciated.
 
G

Greg Maxey

This is not as easy as it may seem since Word considers punctuation a word.
Still, something like this may do:

Sub Scratchmacro()
Dim oSent As Range
Dim i As Long
Dim Count As Long
For Each oSent In ActiveDocument.Sentences
For i = 1 To oSent.Words.Count
If Trim(LCase(oSent.Words(i))) > "a" And Trim(LCase(oSent.Words(i))) <
"z" Then
Count = Count + 1
End If
Next i
oSent.MoveEndWhile Cset:=" ", Count:=wdBackward
oSent.InsertAfter "{" & Count & "}"
Count = 0
Next oSent
End Sub
 

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