How do I programmatically select a sentence?

B

Barbra

In MS Word, I can Ctrl-Click and select an entire sentence. I would like to
reproduce this behavior in a macro, then apply formatting. For example, I'd
like to create a macro that selects whatever sentence the insertion cursor is
currently on, and change the font.

I can do the font changes, but for the life of me can't figure out how to
select the current sentence! Help!
 
J

Jean-Guy Marcil

Barbra was telling us:
Barbra nous racontait que :
In MS Word, I can Ctrl-Click and select an entire sentence. I would
like to reproduce this behavior in a macro, then apply formatting.
For example, I'd like to create a macro that selects whatever
sentence the insertion cursor is currently on, and change the font.

I can do the font changes, but for the life of me can't figure out
how to select the current sentence! Help!

Try

Selection.Sentences(1).Select

to select the sentence at the cursor position.

If you can, avoid using the Selction object, as in these examples:

'_______________________________________
Sub ManipulateSentences()

'Decalre Range variable
Dim SenRange As Range

'Work with sentence at cursor position without selecting it
Set SenRange = Selection.Sentences(1)
SenRange.Font.Bold = True

'Work with second sentence in document without selecting it
Set SenRange = ActiveDocument.Sentences(2)
SenRange.Font.Italic = True

End Sub
'_______________________________________

--
Salut!
_______________________________________
Jean-Guy Marcil - Word MVP
(e-mail address removed)
Word MVP site: http://www.word.mvps.org
 

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