Results 1 to 10 of 10
  1. #1
    New Lounger
    Join Date
    Jul 2002
    Posts
    17
    Thanks
    0
    Thanked 0 Times in 0 Posts

    How to end a repetitive search/replace routine? (Word2000)

    Selection.Find.Execute executes a search you've predefined. But once you've searched (and replaced) a series of words/characters, is there a way to return a "search found nothing" message so that you can break a repetitive loop and End sub?

    I've tried "If Selection.Find = "" Then GoTo 11" in a batch of variations but nothing lets me break the loop!

    Thanks for any help you might suggest.

  2. #2
    Super Moderator
    Join Date
    Dec 2000
    Location
    New York, NY
    Posts
    2,970
    Thanks
    3
    Thanked 29 Times in 27 Posts

    Re: How to end a repetitive search/replace routine? (Word2000)

    Try:

    If Selection.Find.Execute = False Then

  3. #3
    New Lounger
    Join Date
    Jul 2002
    Posts
    17
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: How to end a repetitive search/replace routine? (Word2000)

    Thanks very much, Gary. Is there a particular reference book that would help me find commands like this? I've got a 700 pager by MS, but it is hit and miss by command names rather than an exhaustive
    survey of commands by "family" grouping.

    Anyway, thanks again. You put my wheels back on the track.

  4. #4
    Super Moderator
    Join Date
    Dec 2000
    Location
    New York, NY
    Posts
    2,970
    Thanks
    3
    Thanked 29 Times in 27 Posts

    Re: How to end a repetitive search/replace routine? (Word2000)

    You're welcome. BTW you can also do this with a Do..While or Until loop.

    I don't know of any one exhaustive reference. As far as books by MS, I really liked the Office 97 and Office 2000 VB Programmers Guides - the former being a good beginner's intro and the latter being more advanced. Both of these books are available free online at MSDN. Steven Roman's book on Word macros is concise and has good stuff.

    You might peruse the VBA book reviews at Howard Kaikow's website (just look for a post by him to get the link).

    Another good way to find chunks of useful code is to do a search here on the Lounge - for instance do a search on the VB/VBA forum for the words "Find" and "Loop" with search criteria set to And - get a lot of good hits.

    The MS MVPs' website has some very good VBA material, and there are also links to individual MVP's websites, many of which feature a lot of useful code. Have a look at Bill Coan's site for example.

    Almost forgot - don't forget to try good old VBA Help first - it's certainly the most convenient source!

  5. #5
    4 Star Lounger
    Join Date
    Apr 2001
    Posts
    482
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: How to end a repetitive search/replace routine? (Word2000)

    Gary,
    You mentioned the "Office 97 and Office 2000 VB Programmers Guides".

    I tried searching MSDN for these but am having a hard time finding them. You don't happen to have them bookmarked do you? Or have some other clues to help find them.

    Thanks!!
    Troy

  6. #6
    Super Moderator
    Join Date
    Dec 2000
    Location
    New York, NY
    Posts
    2,970
    Thanks
    3
    Thanked 29 Times in 27 Posts

    Re: How to end a repetitive search/replace routine? (Word2000)

    Troy,

    No surprise - it's well hidden.
    I can't figure out how to get a URL for the individual elements, so here's instructions:

    Go to www.msdn.microsoft.com/library/
    In the left frame you should see a TOC with a tree view that lets you expand elements by clicking on the "+".
    In the TOC, drill your way down through:
    Office Solutions Development > Microsoft Office > Microsoft Office 97 > Office > Microsoft Office 97/Visual Basic Programmer's Guide.
    Expand this one in the TOC and then click on the subelements to see the text appear in the right frame.

    Obvious, right? <img src=/S/nope.gif border=0 alt=nope width=15 height=15>

    The Office 2000 one should be similar to find.

    Gary

  7. #7
    4 Star Lounger
    Join Date
    Apr 2001
    Posts
    482
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: How to end a repetitive search/replace routine? (Word2000)

    I wanted to reply to give the full path to each of these documents, at least as of today, in case someone else goes and looks for them. Gary, you gave me enough to get me there, but it still wasn't easy (no fault of yours), so I wanted to put it all down here for the sake of others. The paths are really not even close after the first level of the TOC.

    For Office 97 Visual Basic Programmer's Guide:

    www.msdn.microsoft.com/library/

    Then in the Table of Contents in the left pane:

    Office Solutions Development
    Microsoft Office
    Microsoft Office 97
    Product Documentation
    Office
    Microsoft Office 97/Visual Basic Programmer's Guide

    For Office 2000 Visual Basic Programmer's Guide

    www.msdn.microsoft.com/library/

    Then in the Table of Contents in the left pane:

    Office Solutions Development
    Microsoft Office Developer
    Microsoft Office 2000 Developer
    Microsoft Office 2000/Visual Basic Programmer's Guide

    Enjoy!!
    Troy

  8. #8
    New Lounger
    Join Date
    Jul 2002
    Posts
    17
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: How to end a repetitive search/replace routine? (Word2000)

    I learned as much from your discussion among yourselves as I did from the original answer to this thread. Thanks for carrying enough to share from your obvious skills.

  9. #9
    Star Lounger
    Join Date
    Jan 2001
    Location
    Iowa, USA
    Posts
    79
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: How to end a repetitive search/replace routine? (Word2000)

    Here's the URL for the VB Guide:
    <A target="_blank" HREF=http://www.msdn.microsoft.com/library/en-us/office97/html/web/fulltoc.asp?frame=true>http://www.msdn.microsoft.com/library/en-u....asp?frame=true</A>

    (I right-clicked on the pane, went into Properties and copied from the URL there.)

    Sue

  10. #10
    Super Moderator
    Join Date
    Dec 2000
    Location
    New York, NY
    Posts
    2,970
    Thanks
    3
    Thanked 29 Times in 27 Posts

    Re: How to end a repetitive search/replace routine? (Word2000)

    Thanks Sue - that tip is definitely a keeper! <img src=/S/trophy.gif border=0 alt=trophy width=15 height=15> <img src=/S/cool.gif border=0 alt=cool width=15 height=15>

Posting Permissions

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