Results 1 to 3 of 3
  1. #1
    3 Star Lounger
    Join Date
    Jan 2001
    Location
    New York
    Posts
    214
    Thanks
    0
    Thanked 0 Times in 0 Posts

    DoAtFind Procedure (Word 97/2k/XP)

    I have found this routine extremely useful when cleaning up documents. I thought I'd post for others.

    <pre>Public Sub DoAtFind()

    Dim gotit As Boolean
    Selection.Find.ClearFormatting
    'Suplly the style to limit the search
    Selection.Find.Style = "Endnote Reference"
    With Selection.Find
    'Supply the search text, leave blank if you want
    'to hit every style specified above
    .Text = ""
    .Replacement.Text = ""
    .Forward = True
    .Wrap = wdFindContinue
    .Format = True
    .MatchCase = False
    .MatchWholeWord = False
    .MatchWildcards = False
    .MatchSoundsLike = False
    .MatchAllWordForms = False
    End With
    gotit = Selection.Find.Execute
    Do While gotit
    'Put what you want to do here...
    Selection.Paragraphs.Reset
    Selection.InsertAfter "*see..."
    'Then move right...
    Selection.MoveRight
    '... and search again
    gotit = Selection.Find.Execute
    Loop
    out:
    Selection.Find.ClearFormatting
    End Sub
    </pre>


  2. #2
    Plutonium Lounger
    Join Date
    Nov 2001
    Posts
    10,550
    Thanks
    0
    Thanked 7 Times in 7 Posts

    Re: DoAtFind Procedure (Word 97/2k/XP)

    I think you need to add
    <pre> If Selection.End = ActiveDocument.Content.End Then Exit Do
    </pre>

    Just before the LOOP. Otherwise you will get an infinite loop if the last thing in the document matches your search criteria.

    StuartR

  3. #3
    3 Star Lounger
    Join Date
    Jan 2001
    Location
    New York
    Posts
    214
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: DoAtFind Procedure (Word 97/2k/XP)

    Good get.

Posting Permissions

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