View Single Post
 
Old 12-24-2023, 02:31 AM
RobiNew RobiNew is offline Windows 10 Office 2016
Competent Performer
 
Join Date: Sep 2023
Posts: 200
RobiNew is on a distinguished road
Default

Hi, Vivka! To get the last name in the first paragraph I have adopted your suggestion: ActiveDocument.Paragraphs(1).Range.Words.Last.Prev ious(unit:=wdWord, Count:=1).Select
For the last name before a comma in the first paragraph I have devised the code here below. Is there a more efficient method to achieve the same result? Thanks!
Code:
ActiveDocument.Paragraphs(1).Range.Select
Dim myVar As String
myVar = Selection
If InStr(1, myVar, ",") > 0 Then
Set oRng = ActiveDocument.Range
oRng.Collapse
oRng.MoveStartUntil Cset:=","
oRng.Collapse wdCollapseEnd
oRng.Previous(unit:=wdWord, Count:=1).Select
Reply With Quote