Results 1 to 3 of 3
  1. #1
    Star Lounger
    Join Date
    Jul 2008
    Posts
    68
    Thanks
    0
    Thanked 0 Times in 0 Posts

    VBA Do Loop Does Not Execute (Word 2003/VBA)

    The second Do Loop in the macro shown below does not execute. The macro is designed to change the followng links and those like them.

    <U><a href="http://www.website.net/CP/Comments/PostNewABC2_R.php?TOP=ON&SeeAlso=Phi 1:10</U>

    <U> Phi 1:12</U>

    <code>
    Sub Test1()
    Do
    With Selection.Find
    .Text = "2</U>"
    .Replacement.Text = ""
    .Forward = True
    .Wrap = wdFindStop
    .Format = False
    .MatchCase = False
    .MatchWholeWord = False
    .MatchWildcards = False
    .MatchSoundsLike = False
    .MatchAllWordForms = False
    End With
    ' Selection.Find.Execute
    If Not Selection.Find.Execute Then Exit Do
    Selection.MoveRight Unit:=wdCharacter, Count:=1, Extend:=wdExtend
    Selection.MoveLeft Unit:=wdCharacter, Count:=1
    Selection.MoveRight Unit:=wdCharacter, Count:=1
    Selection.TypeParagraph
    Selection.Find.ClearFormatting
    With Selection.Find
    .Text = "SeeAlso="
    .Replacement.Text = """>"
    .Forward = False
    .Wrap = wdFindStop
    .Format = False
    .MatchCase = False
    .MatchWholeWord = False
    .MatchWildcards = False
    .MatchSoundsLike = False
    .MatchAllWordForms = False
    End With
    Selection.Find.Execute
    Selection.MoveRight Unit:=wdCharacter, Count:=1
    Selection.EndKey Unit:=wdLine, Extend:=wdExtend
    Selection.MoveLeft Unit:=wdCharacter, Count:=1, Extend:=wdExtend
    Selection.Copy
    Selection.MoveRight Unit:=wdCharacter, Count:=1
    Selection.TypeText Text:=""">"
    Selection.PasteAndFormat (wdPasteDefault)
    Selection.TypeText Text:="</a></U>"
    Selection.Delete Unit:=wdCharacter, Count:=1
    Selection.Delete Unit:=wdCharacter, Count:=1
    Selection.Delete Unit:=wdCharacter, Count:=1
    Selection.Delete Unit:=wdCharacter, Count:=1
    Selection.Delete Unit:=wdCharacter, Count:=1
    Loop

    'this is the second do loop that does not run
    Do
    With Selection.Find
    .Text = "0</U>"
    .Replacement.Text = ""
    .Forward = True
    .Wrap = wdFindStop
    .Format = False
    .MatchCase = False
    .MatchWholeWord = False
    .MatchWildcards = False
    .MatchSoundsLike = False
    .MatchAllWordForms = False
    End With
    'Selection.Find.Execute
    If Not Selection.Find.Execute Then Exit Do
    Selection.MoveRight Unit:=wdCharacter, Count:=1, Extend:=wdExtend
    Selection.MoveLeft Unit:=wdCharacter, Count:=1
    Selection.MoveRight Unit:=wdCharacter, Count:=1
    Selection.TypeParagraph
    Selection.Find.ClearFormatting
    With Selection.Find
    .Text = "SeeAlso="
    .Replacement.Text = """>"
    .Forward = False
    .Wrap = wdFindStop
    .Format = False
    .MatchCase = False
    .MatchWholeWord = False
    .MatchWildcards = False
    .MatchSoundsLike = False
    .MatchAllWordForms = False
    End With
    Selection.Find.Execute
    Selection.MoveRight Unit:=wdCharacter, Count:=1
    Selection.EndKey Unit:=wdLine, Extend:=wdExtend
    Selection.MoveLeft Unit:=wdCharacter, Count:=1, Extend:=wdExtend
    Selection.Copy
    Selection.MoveRight Unit:=wdCharacter, Count:=1
    Selection.TypeText Text:=""">"
    Selection.PasteAndFormat (wdPasteDefault)
    Selection.TypeText Text:="</a></U>"
    Selection.Delete Unit:=wdCharacter, Count:=1
    Selection.Delete Unit:=wdCharacter, Count:=1
    Selection.Delete Unit:=wdCharacter, Count:=1
    Selection.Delete Unit:=wdCharacter, Count:=1
    Selection.Delete Unit:=wdCharacter, Count:=1
    Loop

    End Sub
    </code>

    Thank you in advance for your time and replies.

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: VBA Do Loop Does Not Execute (Word 2003/VBA)

    Does it help if you insert the following line between the two loops?
    <code>
    Selection.HomeKey Unit:=wdStory</code>

  3. #3
    Star Lounger
    Join Date
    Jul 2008
    Posts
    68
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: VBA Do Loop Does Not Execute (Word 2003/VBA)

    Thank you Hans, your suggestion solved the issue.

Posting Permissions

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