Results 1 to 7 of 7

Making a macro loop

Threaded View

  1. #1
    Registered User
    Join Date
    02-21-2024
    Location
    Middx UK
    MS-Off Ver
    2003
    Posts
    68

    Making a macro loop

    I have a macro which identifies a place using a key text ('BX') in the document , and the next one below it. It establishes two placeholders ('First' and 'Next') , and then deletes the text between.

    The only problem is it only works for the first instance of the key text , but then stops.

    Can someone suggest a way to modify it so it runs through to the bottom of the document and finds all examples , and not just the first?

    Sub Macro8()
    '
    ' Macro8 Macro
    '
        Selection.Find.ClearFormatting
        With Selection.Find
            .Text = "BX"
            .Replacement.Text = ""
            .Forward = True
            .Wrap = wdFindContinue
            .Format = False
            .MatchCase = False
            .MatchWholeWord = False
            .MatchAllWordForms = False
            .MatchSoundsLike = False
            .MatchWildcards = True
        End With
        Selection.Find.Execute
        Selection.EndKey Unit:=wdLine
        Selection.TypeText Text:="First"
        Selection.Find.ClearFormatting
        With Selection.Find
            .Text = "BX"
            .Replacement.Text = ""
            .Forward = True
            .Wrap = wdFindContinue
            .Format = False
            .MatchCase = False
            .MatchWholeWord = False
            .MatchAllWordForms = False
            .MatchSoundsLike = False
            .MatchWildcards = True
        End With
        Selection.Find.Execute
        Selection.HomeKey Unit:=wdLine
        Selection.MoveUp Unit:=wdLine, Count:=1
        Selection.TypeText Text:="Next"
        Selection.MoveUp Unit:=wdScreen, Count:=8
        Selection.Find.ClearFormatting
        Selection.Find.Replacement.ClearFormatting
        With Selection.Find
            .Text = "First*Next"
            .Replacement.Text = "^p^p"
            .Forward = True
            .Wrap = wdFindContinue
            .Format = False
            .MatchCase = False
            .MatchWholeWord = False
            .MatchAllWordForms = False
            .MatchSoundsLike = False
            .MatchWildcards = True
        End With
        Selection.Find.Execute Replace:=wdReplaceAll
    End Sub

    Grateful for any advice.

    Last edited by CaMeSuffit; 01-09-2025 at 11:55 PM.
    Currently using Access , Word and Excel 2003

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. [SOLVED] Making Code Loop
    By Bill1234 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 11-22-2023, 08:58 AM
  2. making optionbutton visible or invisible by loop
    By lettersofberk in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 08-13-2013, 12:33 PM
  3. [SOLVED] Making a For loop to loop through a set of cells
    By Smeddlesboy in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 04-06-2012, 08:52 PM
  4. Making a simple loop faster
    By gummi in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 08-23-2008, 07:07 PM
  5. Making macros loop
    By McKCollins in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 07-10-2006, 08:59 AM
  6. Need Help on Making a Loop
    By japorms in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 09-16-2005, 09:05 AM

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1