View Single Post
 
Old 05-18-2015, 11:44 PM
gmayor's Avatar
gmayor gmayor is offline Windows 7 64bit Office 2010 32bit
Expert
 
Join Date: Aug 2014
Posts: 4,142
gmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud of
Default

Code:
Sub DeleteLastWord()
Dim oRng As Range
    'set a range to the paragraph the cursor is in
    Set oRng = Selection.Paragraphs(1).Range
    'omit the paragraph break character
    oRng.End = oRng.End - 1
    'Collapse the range to its end
    oRng.Collapse 0
    'Move backwards to the first space
    oRng.MoveStartUntil Chr(32), wdBackward
    'Optionally include that space
    oRng.Start = oRng.Start - 1
    'Delete the range
    oRng.Delete
lbl_Exit:
    Set oRng = Nothing
    Exit Sub
End Sub
__________________
Graham Mayor - MS MVP (Word) (2002-2019)
Visit my web site for more programming tips and ready made processes www.gmayor.com
Reply With Quote