none
Loop Macro RRS feed

  • Question

  • Greetings.  I have the following Macro which works.  I just do not know how to "Loop" it.  I really appreciate any help.  Thank you.  Will

    _________________________________________________________________________

    Sub Macro1()
    '
    ' Macro1 Macro
    '
    '
        Selection.Find.ClearFormatting
        With Selection.Find
            .Text = "Email: "
            .Replacement.Text = ""
            .Forward = True
            .Wrap = wdFindContinue
            .Format = True
            .MatchCase = True
            .MatchWholeWord = False
            .MatchWildcards = False
            .MatchSoundsLike = False
            .MatchAllWordForms = False
        End With
        Selection.Find.Execute
        Selection.MoveLeft Unit:=wdCharacter, Count:=1
        Selection.EndKey Unit:=wdLine, Extend:=wdExtend
        Selection.Cut
        Windows(2).Activate
        Selection.PasteAndFormat (wdUseDestinationStylesRecovery)
        Windows(1).Activate

    End Sub

    Wednesday, August 21, 2013 2:38 PM

All replies

  • Do you mean every line needs to be looped.

    Sub Macro1()
     '
     ' Macro1 Macro
     '
     '
         Selection.Find.ClearFormatting
         
         With Selection.Find
             .Text = "Email: "
             .Replacement.Text = ""
             .Forward = True
             .Wrap = wdFindContinue
             .Format = True
             .MatchCase = True
             .MatchWholeWord = False
             .MatchWildcards = False
             .MatchSoundsLike = False
             .MatchAllWordForms = False
         End With
         
         With Selection
            Do While .Find.Execute
                   .MoveLeft Unit:=wdCharacter, Count:=1
                   .EndKey Unit:=wdLine, Extend:=wdExtend
                   .Cut
                
                    Windows(2).Activate
                   Selection.PasteAndFormat (wdUseDestinationStylesRecovery)
                   Windows(1).Activate
            Loop
         End With
    
     End Sub


    Best Regards,
    Asadulla Javed, Kolkata
    ---------------------------------------------------------------------------------------------
    Please do not forget to click “Vote as Helpful” if any post helps you and "Mark as Answer”if it solves the issue.

    Thursday, August 22, 2013 6:46 AM
    Answerer