Custom Toolbar Button which Highlights Next & Previous Sentence in Document... 
Author Message
 Custom Toolbar Button which Highlights Next & Previous Sentence in Document...

Hello,

I have created a custom toolbar which contains various buttons.  One of
these buttons is supposed to highlight the previously written sentence in
the document.  I presume this feature would need to somehow detect the last
full-stop to successfully highlight the correct section of the document.

As an add-on to the "Previous Sentence" feature, I would also, like to add a
"Next Sentence" feature aswell.

Could anyone provide any insight into how I might code this type of feature,
in terms of how make the button "detect" the next and/or previous sentence.
I know how to use the highlight feature in Word so that is not a problem,
its just the "sentence" part that is confusing me slightly...

I would appreciate anyone's advice on this issue...

Many thanks,

Thomas Evans



Sun, 30 Jan 2005 18:54:24 GMT  
 Custom Toolbar Button which Highlights Next & Previous Sentence in Document...
[posted and emailed]

Hi Thomas,

You don't need to search for the full stops.  Word has a 'Sentences'
collection, so the coding is pretty straightforward:

Sub SelectPrevSentence
Dim r As Range
Set r = Selection.Sentences(1)
r.Move Unit:=wdSentence, Count:=-2
r.Sentences(1).Select
End Sub

Sub SelectNextSentence
Dim r As Range
Set r = Selection.Sentences(1)
r.Move Unit:=wdSentence, Count:=1
r.Sentences(1).Select
End Sub

Note that a legitimate period in the middle of a sentence (say, in
an abbreviation) is incorrectly interpreted as the end of a sentence,
no matter what follows it.  While you could try to code around this,
it'd probably be more trouble than it's worth.

Hope this helps.


Word MVP FAQ: http://www.mvps.org/word  
Please reply ONLY to the newsgroup.  MVPs do not work for Microsoft.
Userform demystification: http://www.speakeasy.org/~mtangard/userforms.html
"Life is nothing if you're not obsessed."  --John Waters

Quote:

> Hello,

> I have created a custom toolbar which contains various buttons.  One of
> these buttons is supposed to highlight the previously written sentence in
> the document.  I presume this feature would need to somehow detect the last
> full-stop to successfully highlight the correct section of the document.

> As an add-on to the "Previous Sentence" feature, I would also, like to add a
> "Next Sentence" feature aswell.

> Could anyone provide any insight into how I might code this type of feature,
> in terms of how make the button "detect" the next and/or previous sentence.
> I know how to use the highlight feature in Word so that is not a problem,
> its just the "sentence" part that is confusing me slightly...

> I would appreciate anyone's advice on this issue...

> Many thanks,

> Thomas Evans



Mon, 31 Jan 2005 01:52:42 GMT  
 
 [ 2 post ] 

 Relevant Pages 

1. Macro to Jump to Next/Previous Document...

2. next and previous button

3. next and previous button

4. how to add tooltips to custom buttons on custom toolbar

5. Open a custom form with a module-button (not a toolbar button)

6. create custom icon,custom combobox in custom toolbar

7. create custom icon,custom combobox(to insert values)in custom toolbar

8. CUSTOM Office Toolbar Button Icons using VBA

9. Save Custom Toolbar Button

10. Disable or hide buttons on custom toolbar?

11. Custom button on Toolbar

12. Exporting custom toolbars / button bitmaps

 

 
Powered by phpBB® Forum Software