Results 1 to 12 of 12
  1. #1
    Platinum Lounger
    Join Date
    Nov 2001
    Location
    Melbourne, Victoria, Australia
    Posts
    5,016
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Intercepting a dialog Cancel (VBA) (2000 sp-3/ 98SE)

    I think I've seen a solution for this before, but had no luck searching for it. I create a custom menu in the Open/ New events and delete it in the Document_Close procedure. This works well, except if the user Cancels a File -> Close or presses X. This appears to fire the Document_Close procedure, so the menu is lost after the Cancel. Could anyone enlighten me on this one, please?

    Alan
    Attached Images Attached Images

  2. #2
    Super Moderator jscher2000's Avatar
    Join Date
    Feb 2001
    Location
    Silicon Valley, USA
    Posts
    23,112
    Thanks
    5
    Thanked 93 Times in 89 Posts

    Re: Intercepting a dialog Cancel (VBA) (2000 sp-3/

    Let me see if I can restate the problem:

    Scenario 1: Someone chooses Close, they save or don't save, your code kicks in and removes the custom menu, the document closes. This works "as expected."

    Scenario 2: Someone chooses Close, they cancel, your code kicks in and removes the custom menu, but the document stays open. You need a way to prevent your code from removing the custom menu when they cancel the close.

    It seems that you can try to hijack the Yes/No/Cancel part of the process, either with a application-level event or by writing literal code in your close procedure (assuming that isn't too late). I do agree that there must be code snippets for this in the Lounge, maybe on the VBA board? Just a matter of hunting them down. <img src=/S/smile.gif border=0 alt=smile width=15 height=15> Happy hunting!

  3. #3
    Platinum Lounger
    Join Date
    Nov 2001
    Location
    Melbourne, Victoria, Australia
    Posts
    5,016
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Intercepting a dialog Cancel (VBA) (2000 sp-3/

    Yes, that's it "restated" in a nutshell. The hard aspect of searching for this generally, is that the only "key" words I can come up with in a search string appear to be all too common. I might start with a thesaurus search!

    Alan

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

    Re: Intercepting a dialog Cancel (VBA) (2000 sp-3/

    I can't find the relevant threads quickly, but if I remember correctly, it's not really possible to intercept canceling a close, so you may have to live with it.

  5. #5
    5 Star Lounger
    Join Date
    May 2001
    Location
    Stuttgart, Baden-W, Germany
    Posts
    931
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Intercepting a dialog Cancel (VBA) (2000 sp-3/

    I think you may need
    Application.EnableCancelKey = wdCancelDisabled

    <img src=/S/cheers.gif border=0 alt=cheers width=30 height=16> Klaus

  6. #6
    Super Moderator jscher2000's Avatar
    Join Date
    Feb 2001
    Location
    Silicon Valley, USA
    Posts
    23,112
    Thanks
    5
    Thanked 93 Times in 89 Posts

    Re: Intercepting a dialog Cancel (VBA) (2000 sp-3/

    It's an interesting problem, because the events do not always fire in the order you would expect. I created a test template (see attached), created a new document from it, and then tried Save, Close (Yes), Close (Cancel), Close (No) and recorded the results:
    <pre>appWD_DocumentBeforeSave ran! [8:40:41 PM] [Document3]
    This time I am using Save (but it will Save As, of course).

    <img src=/w3timages/blueline.gif width=33% height=2>

    appWD_DocumentBeforeClose ran! [8:41:12 PM] [C:testingEventTest2.doc]
    This is some more test. I will close and save changes.

    Document_Close ran! [8:41:12 PM] [C:testingEventTest2.doc]
    This is some more test. I will close and save changes.

    appWD_DocumentBeforeSave ran! [8:41:14 PM] [C:testingEventTest2.doc]
    This is some more test. I will close and save changes.

    <img src=/w3timages/blueline.gif width=33% height=2>

    appWD_DocumentBeforeClose ran! [8:42:32 PM] [C:TestingEventTest2.doc]
    I typed this and will close and Cancel the close.

    Document_Close ran! [8:42:32 PM] [C:TestingEventTest2.doc]
    I typed this and will close and Cancel the close.

    <img src=/w3timages/blueline.gif width=33% height=2>

    appWD_DocumentBeforeClose ran! [8:43:09 PM] [C:TestingEventTest2.doc]
    Okay, so I am going to close and NOT save now.

    Document_Close ran! [8:43:09 PM] [C:TestingEventTest2.doc]
    Okay, so I am going to close and NOT save now.
    </pre>

    The help page for DocumentBeforeClose implies that you can use it to replace the default Yes/No/Cancel dialog. You might try that and see if it lets you work around the problem
    Attached Files Attached Files

  7. #7
    Star Lounger
    Join Date
    Sep 2001
    Posts
    83
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Intercepting a dialog Cancel (VBA) (2000 sp-3/

    We face the same problem, with some of our products. Sometimes we could solve it with the workaround to define the added Controls/Commandbars as temporary when defining them. Then Word will automatically remove them upon shutdown of Word.

  8. #8
    Platinum Lounger
    Join Date
    Nov 2001
    Location
    Melbourne, Victoria, Australia
    Posts
    5,016
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Intercepting a dialog Cancel (VBA) (2000 sp-3/

    Thanks for all the input on this. I've fiddled from various angles, but still haven't come up with a solution. I can't envisage how to replace the default dialog, and can't spend any more time on it at the moment, for this project anyway. It's something I'd like to nut out though, if at all possible. Hopefully I'll return to this a little later.

    cheers
    Alan

  9. #9
    Super Moderator jscher2000's Avatar
    Join Date
    Feb 2001
    Location
    Silicon Valley, USA
    Posts
    23,112
    Thanks
    5
    Thanked 93 Times in 89 Posts

    Re: Intercepting a dialog Cancel (VBA) (2000 sp-3/

    I can replace the native dialog, but canceling leads to a repetition of the dialog. Not sure why!

    What we need is something like the OnUnload event of COM Add-ins. You then could remove the menu when your template is being unloaded by Word. Word obviously checks on the status of the template (do you want to save changes to the template) as it unloads the document, but I don't see any way to tap into that with VBA. I suppose that some kind of monitoring could be set up in a global add-in, but it does sound like way too much work...

  10. #10
    Platinum Lounger
    Join Date
    Nov 2001
    Location
    Melbourne, Victoria, Australia
    Posts
    5,016
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Intercepting a dialog Cancel (VBA) (2000 sp-3/

    Things seem very flakey in this area. I can set up a Document_Close() routine that removes the custom menu. This will fire, as described previously, before the user has selected Yes/No/Cancel in the Save dialog. If I do choose Cancel, then recreate the menu manually, the effect can not be repeated. From then on, the RemoveMenu routine never fires, regardless of whether the document is closed or the close is cancelled.

    I'd like to find an answer to this one, but I'm it seems all too unreliable as something you'd want to try to implement in a distributed project.

    Alan

  11. #11
    Super Moderator jscher2000's Avatar
    Join Date
    Feb 2001
    Location
    Silicon Valley, USA
    Posts
    23,112
    Thanks
    5
    Thanked 93 Times in 89 Posts

    Re: Intercepting a dialog Cancel (VBA) (2000 sp-3/

    I know that it is preferable in some cases to add menus using VBA, but... I typically use the "lazy" non-code-based approach of creating my custom menu in the template (opening the .DOT and using Tools>Customize). When a document based on the template is opened or switched to, the menu appears, otherwise it doesn't. Occasionally menus from different templates or add-ins will overwrite each other when Word "merges" or "reconciles" the menus and toolbars applicable to a given document; that's a problem I'm happy (well, okay, not happy, but willing) to troubleshoot when it occurs. So I guess that's Plan B if it works in your situation. And it eases the saving of custom icons. <img src=/S/smile.gif border=0 alt=smile width=15 height=15>

  12. #12
    Platinum Lounger
    Join Date
    Nov 2001
    Location
    Melbourne, Victoria, Australia
    Posts
    5,016
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Intercepting a dialog Cancel (VBA) (2000 sp-3/

    Yep <img src=/S/yep.gif border=0 alt=yep width=15 height=15> I think that's the approach I'll have to take here... together with the troubleshooting, no doubt.
    At least I've managed to discover a hidden "run once" feature of MS Word! <img src=/S/laugh.gif border=0 alt=laugh width=15 height=15>

    Alan

Posting Permissions

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