Can it somehow distinguish periods that end abbreviations and numbers
from periods at the end of sentences? If not, you'll get a bit of an
overcount.
- Show quoted text -
I think only if you identify the collection of abbreviations used in
the document. This is exhaustively tested, but the following code
returns an accurate count for the sample text used:
Sub ScratchMacro()
Dim i As Long
Dim oSent As Range
For Each oSent In ActiveDocument.Range.Sentences
oSent.Select
If oSent.Words(1) = Selection.Paragraphs(1).Range.Words(1) _
And oSent.Words(1).Start = Selection.Paragraphs(1).Range.Words
(1).Start Then
Select Case oSent.Words(1)
Case "Dr", "Mr", "Mrs", "etc", "Jr", "Sr"
GoTo Skip
End Select
End If
oSent.MoveEnd wdCharacter, -1
oSent.Collapse wdCollapseEnd
oSent.MoveStartUntil Cset:=" ", Count:=wdBackward
Select Case oSent
Case "Dr.", "Mr.", "Mrs.", "etc.", "Jr.", "Sr."
'Do nothing
Case Else
i = i + 1
End Select
Skip:
Next oSent
Selection.Collapse wdCollapseEnd
MsgBox "Word thinks that there are " & ActiveDocument.Sentences.Count
& " sentences in this bit of text." _
& vbCr + vbCr & "There are really only " & i & "."
End Sub
Mr. Bojangles is having an affair with Mrs. Jones.
My name is Dr. Duck. I am a quack. My dad's name is Donald. People
call him Mr. Duck.
Mrs. Duck met Mr. Duck on Golden Pond.