How to select in whole document all first words in sentences?

A

avkokin

There is a document. In this document I need to select all first words
in every sentences. And then I need apply some style to these words.
How I can do it? Thank you.
 
H

Helmut Weber

Hi avkokin,

The so called discontiguous selection
is only poorly supported by VBA,
or not supported at all.

But you don't have to select anything.

Sub Test455091()
Dim oPrg As Paragraph
For Each oPrg In ActiveDocument.Paragraphs
With oPrg.Range.Words(1)
.Font.Color = wdColorRed
.Font.Bold = True
End With
Next
End Sub

--
Greetings from Bavaria, Germany

Helmut Weber, MVP WordVBA

Win XP, Office 2003
"red.sys" & Chr$(64) & "t-online.de"
 
A

avkokin

Hi avkokin,

The so called discontiguous selection
is only poorly supported by VBA,
or not supported at all.

But you don't have to select anything.

Sub Test455091()
Dim oPrg As Paragraph
For Each oPrg In ActiveDocument.Paragraphs
With oPrg.Range.Words(1)
.Font.Color = wdColorRed
.Font.Bold = True
End With
Next
End Sub

--
Greetings from Bavaria, Germany

Helmut Weber, MVP WordVBA

Win XP, Office 2003
"red.sys" & Chr$(64) & "t-online.de"

Helmut, danke schön.
But it select onlu first words in the paragraphs. How I can select
first words in each sentences?
 
H

Helmut Weber

Hi Antonin,

sorry, my mistake.

Sub Test455091()
Dim oRng As Range
For Each oRng In ActiveDocument.Sentences
With oRng.Words(1)
.Font.Color = wdColorBlue
.Font.Bold = True
End With
Next
End Sub

Note, that "word" and "sentence"
(and others as well) are fuzzy concepts
of natural language and to a certain degree
not computable at all.

--
Greetings from Bavaria, Germany

Helmut Weber, MVP WordVBA

Win XP, Office 2003
"red.sys" & Chr$(64) & "t-online.de"
 
Top