View Single Post
 
Old 12-22-2023, 10:58 AM
RobiNew RobiNew is offline Windows 10 Office 2016
Competent Performer
 
Join Date: Sep 2023
Posts: 200
RobiNew is on a distinguished road
Default Getting the last of three names/words

I'm trying to get the last name in the first paragraph of a doc, but the code here below fails. The string is of this type: John R. Mate or John Rob Mate. Can someone help? Thanks!
Code:
Sub LastName()
Set oRng = ActiveDocument.Range
oRng.Collapse
oRng.MoveEndUntil Cset:=Chr(13)
oRng.Collapse wdCollapseEnd
oRng.Previous(Unit:=wdWord, Count:=1).Select
oRng.Select
'MsgBox oRng.Text
Sub End
Reply With Quote