Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Word / Programming / November 2004

Tip: Looking for answers? Try searching our database.

How do I programmatically select a sentence?

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Barbra - 15 Nov 2004 16:59 GMT
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!
Jean-Guy Marcil - 15 Nov 2004 17:31 GMT
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.
[quoted text clipped - 3 lines]
> 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
'_______________________________________

Signature

Salut!
_______________________________________
Jean-Guy Marcil - Word MVP
jmarcilREMOVE@CAPSsympatico.caTHISTOO
Word MVP site: http://www.word.mvps.org


Rate this thread:






 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.