B
BHW
Hi,
I found some old code, from Helmut of Bavaria I believe, that is
supposed to find long sentences in a document:
Sub test002()
Dim rDcm As Range ' the documents main story range
Dim oWrd As Object ' a word
Dim oSnt As Object ' a sentence
Dim oPrg As Paragraph ' a paragraph
Dim lWrd As Long ' a counter for words
Dim lSnt As Long ' a counter for sentences
Dim lPrg As Long ' a counter for paragraphs
Set rDcm = ActiveDocument.Range
For Each oPrg In rDcm.Paragraphs
lPrg = lPrg + 1
lSnt = 0
For Each oSnt In oPrg.Range.Sentences
If Len(oSnt) > 50 Then
oSnt.Comments.Add _
Range:=oSnt, _
Text:="sentence too long"
End If
lSnt = lSnt + 1
lWrd = 0
' For Each oWrd In oSnt.Words
' lWrd = lWrd + 1
' If Len(oWrd) = 1 Then
' oWrd.Comments.Add _
' Range:=oWrd, _
' Text:="1 character word"
' End If
' Next
Next
Debug.Print lPrg, lSnt, lWrd
' paragraph, sentence, words
Next
End Sub
I ran this macro and it seems to comment *every* sentence, regardless
of the length. Does anyone know why? Has anyone improved on this code?
I'd like to find long sentences in a document and consider revising
them. Either commenting or highlighting them would be fine.
Thanks, Bruce
I found some old code, from Helmut of Bavaria I believe, that is
supposed to find long sentences in a document:
Sub test002()
Dim rDcm As Range ' the documents main story range
Dim oWrd As Object ' a word
Dim oSnt As Object ' a sentence
Dim oPrg As Paragraph ' a paragraph
Dim lWrd As Long ' a counter for words
Dim lSnt As Long ' a counter for sentences
Dim lPrg As Long ' a counter for paragraphs
Set rDcm = ActiveDocument.Range
For Each oPrg In rDcm.Paragraphs
lPrg = lPrg + 1
lSnt = 0
For Each oSnt In oPrg.Range.Sentences
If Len(oSnt) > 50 Then
oSnt.Comments.Add _
Range:=oSnt, _
Text:="sentence too long"
End If
lSnt = lSnt + 1
lWrd = 0
' For Each oWrd In oSnt.Words
' lWrd = lWrd + 1
' If Len(oWrd) = 1 Then
' oWrd.Comments.Add _
' Range:=oWrd, _
' Text:="1 character word"
' End If
' Next
Next
Debug.Print lPrg, lSnt, lWrd
' paragraph, sentence, words
Next
End Sub
I ran this macro and it seems to comment *every* sentence, regardless
of the length. Does anyone know why? Has anyone improved on this code?
I'd like to find long sentences in a document and consider revising
them. Either commenting or highlighting them would be fine.
Thanks, Bruce