Results 1 to 3 of 3
  1. #1
    5 Star Lounger
    Join Date
    Feb 2001
    Location
    Australia
    Posts
    676
    Thanks
    28
    Thanked 2 Times in 2 Posts

    Looping macro (Word 2000)

    I need to create a macro that will delete multiple blocks of text, each of which is delineated by a pair of beginning and ending markers. I can record a simple macro to find the first beginning marker and delete through to the first ending marker, but how can I make the macro loop to repeat this for every pair of markers in the document?

    Example:

    Some text
    {Begin}
    Delete this
    {End}
    Some more text
    {Begin}
    Delete this
    {End}
    Still more text
    {Begin}
    Delete this
    {End}
    ...etc.

  2. #2
    Plutonium Lounger
    Join Date
    Nov 2001
    Posts
    10,550
    Thanks
    0
    Thanked 7 Times in 7 Posts

    Re: Looping macro (Word 2000)

    Easiest way to do this is with a Wildcard replace...

    <code>Sub ReplaceDelimitedText
    Selection.Find.ClearFormatting
    Selection.Find.Replacement.ClearFormatting
    With Selection.Find
    .Text = "{Begin}*{End}"
    .Replacement.Text = ""
    .Forward = True
    .Wrap = wdFindContinue
    .Format = False
    .MatchCase = False
    .MatchWildcards = True
    End With
    Selection.Find.Execute Replace:=wdReplaceAll
    End Sub</code>

    StuartR

  3. #3
    5 Star Lounger
    Join Date
    Feb 2001
    Location
    Australia
    Posts
    676
    Thanks
    28
    Thanked 2 Times in 2 Posts

    Re: Looping macro (Word 2000)

    That's perfect, thanks for your reply.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •