PDA

View Full Version : [SOLVED:] Multiple Text Selection



Paul_Hossler
09-15-2016, 07:56 PM
If I select the red paragraph, and then control-click the green paragraph to have 2 non-contiguous text ranges selected, my simple word count macro

17089



Option Explicit

Sub WordCount()
Dim iWords As Long

With Selection
Call MsgBox( _
"There are:" & vbCrLf & vbCrLf & _
" Characters : " & Format(.Characters.Count, "#,##0") & vbCrLf & _
" Words : " & Format(.Words.Count, "#,##0") & vbCrLf & _
" Sentences : " & Format(.Sentences.Count, "#,##0") & vbCrLf & _
" Paragraphs : " & Format(.Paragraphs.Count, "#,##0"), vbInformation + vbOKOnly, "Selection Statistics")
End With

End Sub


only report the last (green) paragraph

I know Word is smart enough to realize that there are 2 pieces to the Selection (make Bold gets both), but is there a Word equivalent to Excel's .Area that will allow accurate counts?

gmaxey
09-16-2016, 07:10 AM
Paul,

I don't think so. As with so many other things about Word, Microsoft has simply never updated VBA access to changes in the UI. This explains the limitations fairly well:
https://support.microsoft.com/en-us/kb/288424