View Single Post
 
Old 09-24-2022, 12:14 PM
Stephen Ray Stephen Ray is offline Windows 10 Office 2016
Advanced Beginner
 
Join Date: Sep 2018
Location: Kansas
Posts: 34
Stephen Ray is on a distinguished road
Default Range For Last Line/Paragraph - To Find Date

My friends, from years ago, this forum helped me with the code below.
In the Word Document, It finds a date in a format like this: 9/24/2022 10:04:36 AM
It works great.
But now there is more than one date in the document. So I want it to find only the date on the last line of the document, the last paragraph.

How can I change this to find the date in the last line/paragraph of the document?

This is the old code:

Code:
Dim oRng As Word.Range
  Set oRng = ActiveDocument.Range
  With oRng.Find
    .Text = "[0-9]{1,2}\/"
    .MatchWildcards = True
    If .Execute Then
      oRng.End = oRng.Paragraphs(1).Range.End - 1
      If IsDate(oRng.Text) Then
         ActiveDocument.Range.InsertAfter "It took this long: " & fcnCalcSpanStart_Finish(oRng.Text, Now)
      End If
    End If
 End With

Last edited by macropod; 09-24-2022 at 03:26 PM. Reason: Added code tags
Reply With Quote