+ Reply to Thread
Results 1 to 11 of 11

Using CommandBars - How to make Word wait....

  1. #1
    Forum Contributor
    Join Date
    01-18-2013
    Location
    London
    MS-Off Ver
    Excel 2003
    Posts
    641

    Using CommandBars - How to make Word wait....

    In my VBA , I use this code at the end of a Find and Replace routine to interrupt the routine and allow me to step through individual matches :

    Please Login or Register  to view this content.
    If it's the last line of the macro then it works fine and exits when the last match has been executed.

    However , if it is followed by any other routine then Word ignores it and ploughs on past , only showing the Find and Replace dialog momentarily.

    Is there a way to make the macro stop and wait for the finds and replaces to be gone through by the user , before continuing to the next part of the macro?

    Grateful for any advice.

    Last edited by CDandVinyl; 06-17-2020 at 09:38 PM.
    Using Excel , Word and Access 2003 - For the whole of 2024

  2. #2
    Forum Expert macropod's Avatar
    Join Date
    12-22-2011
    Location
    Canberra, Australia
    MS-Off Ver
    Word, Excel & Powerpoint 2003 & 2010
    Posts
    3,726

    Re: Using CommandBars - How to make Word wait....

    For an interactive Find/Replace, see for example: https://www.msofficeforums.com/31726-post17.html
    Cheers,
    Paul Edstein
    [Fmr MS MVP - Word]

  3. #3
    Forum Contributor
    Join Date
    01-18-2013
    Location
    London
    MS-Off Ver
    Excel 2003
    Posts
    641

    Re: Using CommandBars - How to make Word wait....

    OK thanks. I had a look at the link with a view to adapting to my circumstance. The coding on the link page seems to makes references to Excel , and I would imagine would be hard to unpick. I'll keep at it.

    This seems more complex a problem than I was hoping for. I had in mind some small piece of code , perhaps a message box arrangement , to make Word wait while the search / replace interrogation was complete before proceeding with the next part of the macro.



  4. #4
    Forum Expert macropod's Avatar
    Join Date
    12-22-2011
    Location
    Canberra, Australia
    MS-Off Ver
    Word, Excel & Powerpoint 2003 & 2010
    Posts
    3,726

    Re: Using CommandBars - How to make Word wait....

    Quote Originally Posted by CDandVinyl View Post
    The coding on the link page seems to makes references to Excel , and I would imagine would be hard to unpick. I'll keep at it.
    While it does indeed get the Find/Replace expressions from an Excel workbook, that's not the part you need to concern yourself with. You should focus your efforts on the 'With ActiveDocument.Range' ... 'End With' block.

  5. #5
    Forum Contributor
    Join Date
    01-18-2013
    Location
    London
    MS-Off Ver
    Excel 2003
    Posts
    641

    Re: Using CommandBars - How to make Word wait....

    Ok Thanks. After some floundering around , I've achieved some success. I used a portion of the code from the link you sent and have it working in the context of my macro. ()

    I'm starting the search and replace section with

    Please Login or Register  to view this content.
    and adding this code to the end

    Please Login or Register  to view this content.
    This allows me to step through the instances found by the search parameter. Once finished it runs on to the remaining parts of the macro with no issues and completes successfully. Perfect.

    One question : Using the message box I'm using Yes to replace , No to skip over , and the Cancel button exits the macro. What I'd like ideally is for the Cancel button to replace all remaining finds in the text from that point. I'm not sure how to modify

    Please Login or Register  to view this content.
    to do this. I tried a variety of things but could not get the desired outcome ...

    Can you advise?

    Grateful for your help.

    Last edited by CDandVinyl; 06-18-2020 at 10:19 PM.

  6. #6
    Forum Expert macropod's Avatar
    Join Date
    12-22-2011
    Location
    Canberra, Australia
    MS-Off Ver
    Word, Excel & Powerpoint 2003 & 2010
    Posts
    3,726

    Re: Using CommandBars - How to make Word wait....

    For example:
    Please Login or Register  to view this content.

  7. #7
    Forum Contributor
    Join Date
    01-18-2013
    Location
    London
    MS-Off Ver
    Excel 2003
    Posts
    641

    Re: Using CommandBars - How to make Word wait....

    Yes - very good. That does it.

    The anomaly is that it also clears out the finds that I'd previously skipped over.

    Earlier in the macro , I've said Yes to replace certain of the finds , and No to keep some. I'm finding that if I use Cancel to replace all then it's taking them all out , even the ones I'd earlier wanted to keep.

    Is there a way for the Cancel button to replace all below the point it is in the text?

    Thanks again.

  8. #8
    Forum Expert macropod's Avatar
    Join Date
    12-22-2011
    Location
    Canberra, Australia
    MS-Off Ver
    Word, Excel & Powerpoint 2003 & 2010
    Posts
    3,726

    Re: Using CommandBars - How to make Word wait....

    Are you using:
    Please Login or Register  to view this content.
    ?

  9. #9
    Forum Contributor
    Join Date
    01-18-2013
    Location
    London
    MS-Off Ver
    Excel 2003
    Posts
    641

    Re: Using CommandBars - How to make Word wait....

    No , I'm using

    Please Login or Register  to view this content.
    This is the code I have presently :

    Please Login or Register  to view this content.
    maybe you can see what's tripping it up....


  10. #10
    Forum Expert macropod's Avatar
    Join Date
    12-22-2011
    Location
    Canberra, Australia
    MS-Off Ver
    Word, Excel & Powerpoint 2003 & 2010
    Posts
    3,726

    Re: Using CommandBars - How to make Word wait....

    Quote Originally Posted by CDandVinyl View Post
    No , I'm using

    Please Login or Register  to view this content.
    maybe you can see what's tripping it up....
    See my previous reply...

  11. #11
    Forum Contributor
    Join Date
    01-18-2013
    Location
    London
    MS-Off Ver
    Excel 2003
    Posts
    641

    Re: Using CommandBars - How to make Word wait....

    Ok I see. I thought you were enquiring rather than suggesting. I've amended that now and it's retaining the elements I wanted to keep so that's job done. Many thanks. I'm grateful for your time and considerable expertise.

    Problem solved!


+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Make userform wait
    By samot79 in forum Excel General
    Replies: 2
    Last Post: 02-01-2017, 07:30 AM
  2. [SOLVED] How to make vba to wait until I select another cell
    By tamilvendhan in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 10-01-2013, 06:08 AM
  3. [SOLVED] Make Excel wait
    By Test123Test in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 09-23-2013, 01:30 PM
  4. Make macro wait for process to complete
    By pjaj in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 08-13-2012, 01:05 AM
  5. Make macro wait for process to complete
    By shawnh in forum Excel Programming / VBA / Macros
    Replies: 21
    Last Post: 02-16-2010, 07:52 PM
  6. Make Modaless form wait for 'OK' click
    By duckboy1981 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 08-05-2009, 07:42 AM
  7. Make it wait
    By Rhapsodie in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 03-05-2009, 03:47 PM

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1