Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 03-09-2016, 01:26 PM
poetofpiano poetofpiano is offline Help Writing more Customized Command to Select Next Sentence in Microsoft Word Windows 8 Help Writing more Customized Command to Select Next Sentence in Microsoft Word Office 2013
Novice
Help Writing more Customized Command to Select Next Sentence in Microsoft Word
 
Join Date: Sep 2015
Posts: 25
poetofpiano is on a distinguished road
Default

I really cannot thank you enough for your help gmaxey. That one is virtually perfect!



I fooled around with another method of accomplishing my goal:

Code:
Selection.MoveRight Unit:=wdSentence, Count:=1, extend:=wdExtend

Do While Strings.Right(Selection.Range.Text, 4) = "Mr. " Or Strings.Right(Selection.Range.Text, 5) = "Mrs. " Or Strings.Right(Selection.Range.Text, 1) = vbCr
  Selection.MoveRight Unit:=wdSentence, Count:=1, extend:=wdExtend
Loop

End Sub
It is not nearly as elegant as yours, and adding new abbreviations to be excluded is much more cumbersome than in yours, so if you have any suggestions I would gladly use them. It functions exactly the same as yours except that with yours, if there is one or more blank lines below the last sentence of a Paragraph, it will not select any further than that last sentence, whereas mine will continue to select the blank lines below one at a time. Not a huge difference at all — I can’t think of a time where I wanted to select blank lines below a paragraph.

Again, thank you gmaxey and macropod!
Reply With Quote
  #2  
Old 03-09-2016, 01:53 PM
gmaxey gmaxey is offline Help Writing more Customized Command to Select Next Sentence in Microsoft Word Windows 7 32bit Help Writing more Customized Command to Select Next Sentence in Microsoft Word Office 2010 (Version 14.0)
Expert
 
Join Date: May 2010
Location: Brasstown, NC
Posts: 1,636
gmaxey is just really nicegmaxey is just really nicegmaxey is just really nicegmaxey is just really nicegmaxey is just really nice
Default

Try this:

Code:
Sub ScratchMacro()
'A basic Word macro coded by Greg Maxey
Dim strAbbr, i As Long
Dim oRng As Range
    strAbbr = ".Mr.Mrs.Ms.etc."
    With Selection
      Set oRng = Selection.Range
      On Error GoTo Err_End
      Do While .Characters.Last.Next = vbCr
        .MoveEnd wdCharacter, 1
      Loop
        
      Set oRng = Selection.Range
      .Collapse 0
      If .End <= .Sentences.First.End Then .MoveEnd wdSentence, 1
      Do While InStr(strAbbr, "." & Trim(.Words.Last.Previous.Words.First) & ".") > 0 _
               Or Selection.Text = vbCr _
               Or Right(.Text, 3) = "., "
        .MoveEnd wdSentence, 1
      Loop
      oRng.End = .End
    End With
    Do While oRng.Characters.Last = vbCr Or oRng.Characters.Last = Chr(11)
      oRng.MoveEnd wdCharacter, -1
    Loop
    oRng.Select
lbl_Exit:
  Exit Sub
Err_End:
  Resume lbl_Exit
End Sub
__________________
Greg Maxey
Please visit my web site at http://www.gregmaxey.com/
Reply With Quote
Reply



Similar Threads
Thread Thread Starter Forum Replies Last Post
Select backstage Print command programmatically NobodysPerfect Excel Programming 0 04-23-2015 08:52 AM
Select the whole sentence when a word has been modified gloos Word VBA 1 04-14-2015 10:24 PM
Help Writing more Customized Command to Select Next Sentence in Microsoft Word VBA code for Microsoft Word macro — select text and insert footnote ndnd Word VBA 10 01-06-2015 01:47 PM
Help Writing more Customized Command to Select Next Sentence in Microsoft Word Writing fractions using the Mathematics programme of Microsoft Word 2010 Microsoftenquirer1000 Word 8 11-19-2014 02:10 PM
Microsoft Word 2003: casual style from the writing box? intooutfrom Word 0 01-04-2010 01:52 PM

Other Forums: Access Forums

All times are GMT -7. The time now is 08:18 PM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2025, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2025 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft