View Single Post
 
Old 12-24-2023, 03:49 AM
vivka vivka is offline Windows 7 64bit Office 2016
Expert
 
Join Date: Jul 2023
Posts: 293
vivka is on a distinguished road
Default

Hi, RobiNew! What if there are many words that start with a capital letter and are followed by a comma in a paragraph? Which one should be selected? If the wrd to select is near the paragraph's start or end, it will be possible to find the 1st from the paragraph's start or end instance of a comma & do the rest of the job.
The code below (it's your's but slightly shortened) finds the 1st occurrence of a comma in the 1st paragraph & selects ANY wd (not only a caplitalized wd) before it. It will be OK if you are sure there's a last name before the 1st occurrence of a comma:
Code:
Sub Find_Select()
ActiveDocument.Paragraphs(1).range.Select
   If InStr(1, selection, ",") > 0 Then
      selection.Collapse
      selection.MoveStartUntil Cset:=","
      selection.Previous(unit:=wdWord, count:=1).Select
   End If
End Sub
Reply With Quote