View Single Post
 
Old 05-19-2023, 11:00 PM
gmayor's Avatar
gmayor gmayor is offline Windows 10 Office 2019
Expert
 
Join Date: Aug 2014
Posts: 4,144
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

You can do it with one macro - provided your samples are an accurate reflection of the documents.
Code:
Option Explicit

Sub SelectAddress()
'Graham Mayor - https://www.gmayor.com - Last updated - 20 May 2023
Dim oPara As Paragraph
Dim oRng As Range
Dim lPara As Long
Dim bTop As Boolean
    Set oRng = ActiveDocument.Range
    oRng.Collapse 1
    For lPara = 1 To ActiveDocument.Paragraphs.Count
        Set oPara = ActiveDocument.Paragraphs(lPara)
        If Len(oPara.Range) > 4 Then
            oRng.End = oPara.Range.End
        Else
            Exit For
        End If
    Next lPara
    If oRng.Paragraphs.Count > 2 Then
        bTop = True
        oRng.Select
        GoTo lbl_Exit
    End If
    
    If Not bTop = True Then
        Set oRng = ActiveDocument.Range
        oRng.Collapse 0
        For lPara = ActiveDocument.Paragraphs.Count To 1 Step -1
            Set oPara = ActiveDocument.Paragraphs(lPara)
            If Len(oPara.Range) > 4 Then
                oRng.Start = oPara.Range.Start
            Else
                Exit For
            End If
        Next lPara
        If oRng.Paragraphs.Count > 2 Then
            oRng.Select
        End If
    End If
    
lbl_Exit:
    Set oRng = Nothing
    Set oPara = 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