Stop a Find.Execute loop

Discussion in 'Word VBA Beginners' started by AG, Apr 28, 2011.

  1. AG

    AG Guest

    Hello,

    This is probably easy, but I don't find the answer. Here is my macro (Office 2007). It enumerates my titles, but when reaching the last one, it loops over it again and again. I have tried the different .Wrap possibilities, but they all give the same result. How can I stop my search after having enumerated all my titles?

    AG.

    Sub macro1()
    Dim rgDcm As Range

    Set rgDcm = ActiveDocument.Range

    With rgDcm.Find
    .ClearFormatting
    .Style = ActiveDocument.Styles("Titre 1")
    .Replacement.ClearFormatting
    .Text = ""
    .Forward = True
    .Wrap = wdFindStop
    .Format = True
    .MatchCase = False
    .MatchWholeWord = False
    .MatchWildcards = False
    .MatchSoundsLike = False
    .MatchAllWordForms = False
    End With

    Do While rgDcm.Find.Execute
    MsgBox rgDcm.Text
    Loop
    End Sub
     
    AG, Apr 28, 2011
    #1
    1. Advertisements

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Petra Liverani

    Loop Find Text with MsgBox

    Petra Liverani, Aug 2, 2003, in forum: Word VBA Beginners
    Replies:
    4
    Views:
    250
    Petra Liverani
    Aug 4, 2003
  2. ES

    How to execute macro for First Page ONLY

    ES, Aug 26, 2003, in forum: Word VBA Beginners
    Replies:
    3
    Views:
    122
  3. Petra Liverani

    Find loop

    Petra Liverani, Dec 29, 2003, in forum: Word VBA Beginners
    Replies:
    2
    Views:
    70
    Petra Liverani
    Dec 30, 2003
  4. Pat Cortez

    Find and Loop Macro

    Pat Cortez, Mar 4, 2004, in forum: Word VBA Beginners
    Replies:
    4
    Views:
    94
    Pat Cortez
    Mar 4, 2004
  5. Joanne

    Execute Method for Find Object

    Joanne, Feb 8, 2005, in forum: Word VBA Beginners
    Replies:
    5
    Views:
    156
  6. Greg

    Find .execute still not clicking

    Greg, Mar 28, 2005, in forum: Word VBA Beginners
    Replies:
    4
    Views:
    82
  7. Jeff Mitteer
    Replies:
    9
    Views:
    151
    Greg Maxey
    Dec 13, 2006
  8. Replies:
    2
    Views:
    161
Loading...