VBA Word - Creating a Loop with an IF statement

Using VBA in Word, I need to create an IF Loop statement.  I've listed the code below, basically I need to repeat a set of code which does the following:  1.  Searches my document for a constant alfanumberic number (5722SSI) and adds a page break. It's a pretty big doc, so I'm looking to report this process until it doesn't find the 5722SSI number on the doc.  The reason I use the 5722SSI is because that is always constant and serves as a breaking point for a page break.  Hope this explains what I'm trying to do.  Here's my SuDo Code:

Sub CPFPGBRK()
'
' CPFPGBRK Macro
' Macro recorded 6/30/2005 by Alex Romo
'
Dim SLIC As Integer

If SLIC = "5722SSI" Then
  N = 1
  Do While Not ????????
        SLIC = "5722SSI"
        N = N + 1
 Loop
End If

' Selects font size and searches for the license internal code number 5722SSI.
' Once the last internal code number is found it will end the loop.

    Selection.WholeStory
    Selection.Font.Size = 6
    Selection.MoveLeft Unit:=wdCharacter, Count:=1
    Selection.Find.ClearFormatting
    With Selection.Find
        .Text = "5722ss1"
        .Replacement.Text = ""
        .Forward = True
        .Wrap = wdFindContinue
        .Format = False
        .MatchCase = False
        .MatchWholeWord = False
        .MatchWildcards = False
        .MatchSoundsLike = False
        .MatchAllWordForms = False
    End With
    Selection.Find.Execute
    Selection.Find.Execute
    Selection.MoveLeft Unit:=wdCharacter, Count:=1
    Selection.InsertBreak Type:=wdPageBreak
    Selection.Find.ClearFormatting
AlexhomarAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

gary_jCommented:
Dim SLIC As Integer

If SLIC = "5722SSI" Then
  N = 1
  Do While Not ????????
        SLIC = "5722SSI"
        N = N + 1
 Loop
End If

I haven't really figured out what you want to do here, but I use a variable like blnFound for this kind of thing
e.g.,

dim blnFound as boolean

blnFound = true
do
   'do whatever you need to do here

   'determine whether or not you can find your '5722SSi'
   if conditionisnotmet then
         blnFound = false
   End if
loop until blnFound = false
edwardiiiCommented:
Hi, Alexhomar.

Does this code do what you wish?:

    Dim objSentence As Range
    For Each objSentence In ActiveDocument.Words
           
        objSentence.Find.ClearFormatting
        With objSentence.Find
           
            .Text = "<5722SSI>"
            .Replacement.Text = ""
            .Forward = True
            .Wrap = wdFindStop
            .Format = False
            .MatchCase = False
            .MatchWholeWord = True
            .MatchAllWordForms = False
            .MatchSoundsLike = False
            .MatchWildcards = True
        End With
        objSentence.Find.Execute
       
        If objSentence.Find.Found Then
           objSentence.Select
           Selection.Font.Size = 6
           Selection.MoveLeft Unit:=wdCharacter, Count:=1
           Selection.InsertBreak Type:=wdPageBreak
         End If
       
    Next

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
AlexhomarAuthor Commented:
Thanks Gary_J and edwardiii.  I was able to modify the code using both of your answers.  My imported Word document is no longer a daunting task when resizing and page breaking properly.  The client that receives this report has requested 20 other similar reports.  Thanks to both your expertise , this task is in the bag.  Sincerely, Alex
edwardiiiCommented:
Anytime :)
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic Classic

From novice to tech pro — start learning today.