View Single Post
 
Old 08-21-2024, 06:59 PM
Guessed's Avatar
Guessed Guessed is offline Windows 10 Office 2016
Expert
 
Join Date: Mar 2010
Location: Canberra/Melbourne Australia
Posts: 4,163
Guessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant future
Default

This should get you started. Note that your concept might miss the last entry if it doesn't end with a # (which in your sample code appears to be a start point rather than a bracketing)
Code:
Sub Macro1()
  Dim aRng As Range, sFound As String
  
  Set aRng = ActiveDocument.Range
  With aRng.Find
    .ClearFormatting
    .Replacement.ClearFormatting
    .Text = "#*#"
    .Forward = True
    .Wrap = wdFindStop
    .Format = False
    .MatchWholeWord = False
    .MatchWildcards = True
    Do While .Execute = True
      aRng.MoveStart Unit:=wdCharacter, Count:=1
      aRng.MoveEnd Unit:=wdCharacter, Count:=-2
      If Len(aRng.Text) > 32766 Then
        Debug.Print "Oversize Block starting: " & aRng.Paragraphs(1).Range.Text
      Else
        'Do something with the found content
        MsgBox aRng.Text
      End If
      aRng.Collapse Direction:=wdCollapseEnd
      If aRng.End = ActiveDocument.Range.End Then
        Exit Do
      Else
        aRng.End = ActiveDocument.Range.End
        aRng.Select
      End If
    Loop
  End With
End Sub
__________________
Andrew Lockton
Chrysalis Design, Melbourne Australia
Reply With Quote