View Single Post
 
Old 04-18-2023, 05:24 PM
Guessed's Avatar
Guessed Guessed is offline Windows 10 Office 2016
Expert
 
Join Date: Mar 2010
Location: Canberra/Melbourne Australia
Posts: 4,176
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

The simplest way is to use a MsgBox to ask if the user wants to continue on to the next location. You can click Yes (or type Y) to find next or No (or type N) to stop the macro. If you want to change the text, you type N to end the macro, make the desired change and then start the macro again.
Code:
Sub FindNextSquareBrackets()
  Dim iResp As Integer, aRng As Range
  Set aRng = ActiveDocument.Range(Selection.Range.Start, ActiveDocument.Range.End)
  With aRng.Find
    .ClearFormatting
    .Replacement.ClearFormatting
    .Text = "(\[)(*)(\])"
    .Replacement.Text = ""
    .Forward = True
    .Wrap = wdFindContinue
    .Format = False
    .MatchCase = False
    .MatchWholeWord = False
    .MatchAllWordForms = False
    .MatchSoundsLike = False
    .MatchWildcards = True
    Do While .Execute
      aRng.Select
      iResp = MsgBox("Goto Next?", vbYesNo, "Found one")
      If iResp = vbNo Then Exit Sub
      aRng.Collapse Direction:=wdCollapseEnd
      aRng.End = ActiveDocument.Range.End
    Loop
  End With
End Sub
__________________
Andrew Lockton
Chrysalis Design, Melbourne Australia
Reply With Quote