Results 1 to 14 of 14
  1. #1
    Gold Lounger
    Join Date
    Dec 2000
    Location
    Hollywood (sorta), California, USA
    Posts
    2,759
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Function Override Not Functioning (Word 2002)

    Is there any known reason why

    Sub FileSave()
    MsgBox "VBA FileSave Method Overridden."
    End Sub

    would NOT override Word's built in FileSave method?

    I've put this simple test sub in Norma.dot and in a global template. Word
    2002 does not "see" this sub and just does its own thing when File | Save is
    invoked from keyboard, menu or toolbar. Ok, what's up here?
    Kevin <IMG SRC=http://www.wopr.com/w3tuserpics/Kevin_sig.gif alt="Keep the change, ya filthy animal...">
    <img src=/w3timages/blackline.gif width=33% height=2><img src=/w3timages/redline.gif width=33% height=2><img src=/w3timages/blackline.gif width=33% height=2>

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

    Re: Function Override Not Functioning (Word 2002)

    Works for me in the Dutch version of Word 2002 SP-2. It doesn't matter whether I give the macro the English or Dutch command name. I hope you can see in the screenshot that the Save toolbar button has been pressed. It doesn't intercept the File/Save command in the Visual Basic Editor, however.

  3. #3
    Gold Lounger
    Join Date
    Dec 2000
    Location
    Hollywood (sorta), California, USA
    Posts
    2,759
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Function Override Not Functioning (Word 2002)

    Thanks for testing, Hans.

    I think I've just discovered something I never know before:

    I slowed things down and paid a little more attention to when
    Word ignored the FileSave substitute: when I click either the
    document close X or the AppClose Big X. In those to instances, Word
    just does it's own thing.

    Test this on a new dirty document:
    1) Click the doc X.
    2) After the "Do you want to Save.." dialog appears, click Yes.

    What executes, our substitute code or Word's Build in SaveAs?

    It's not my code over here.
    Kevin <IMG SRC=http://www.wopr.com/w3tuserpics/Kevin_sig.gif alt="Keep the change, ya filthy animal...">
    <img src=/w3timages/blackline.gif width=33% height=2><img src=/w3timages/redline.gif width=33% height=2><img src=/w3timages/blackline.gif width=33% height=2>

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

    Re: Function Override Not Functioning (Word 2002)

    If you want to intercept every possible event that could save the document then I think you want the DocumentBeforeSave event. You need to set this up as an application class event, if you need to prevent the save from taking place then you can set the Cancel parameter like this...

    Private Sub App_DocumentBeforeSave(ByVal Doc As Document, SaveAsUI As Boolean, Cancel As Boolean)
    <font color=448800>' Put your code here </font color=448800>
    Cancel = True
    End Sub

    StuartR

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

    Re: Function Override Not Functioning (Word 2002)

    Kevin,

    Apparently the code executed when a document is closed bypasses the standard FileSave routine. To catch this, you can use the DocumentBeforeClose and DocumentBeforeSave application level events - set their Cancel argument to True to avoid the document being closed or saved. If you set Cancel = True in the DocumentBeforeSave event, you'll still get asked if you want to save the document (this is different from the FileSave macro), but the Save As dialog is not shown.

  6. #6
    Gold Lounger
    Join Date
    Dec 2000
    Location
    Hollywood (sorta), California, USA
    Posts
    2,759
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Function Override Not Functioning (Word 2002)

    I've been working with those events too. Unfortunately, (for us, but obviously not for MS!)
    they too are poorly implemented. I don't have the time right now to post the particulars.

    I hope to set down my observations later.
    Kevin <IMG SRC=http://www.wopr.com/w3tuserpics/Kevin_sig.gif alt="Keep the change, ya filthy animal...">
    <img src=/w3timages/blackline.gif width=33% height=2><img src=/w3timages/redline.gif width=33% height=2><img src=/w3timages/blackline.gif width=33% height=2>

  7. #7
    Gold Lounger
    Join Date
    Dec 2000
    Location
    Hollywood (sorta), California, USA
    Posts
    2,759
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Function Override Not Functioning (Word 2002)

    Thanks, Stu,
    but we're running into problems when that event and the Beforeclose are
    triggerd by the Big X. So far, we've seen that if the user cancels the save (or
    the doc close) the Big X close is also cancelled. This is not the default Word
    behavior: each dirty doc produces a prompt and the actiion taken effects only
    that document; then Word closes. We can't get this to work if you set cancel = true
    in either of these events.
    Kevin <IMG SRC=http://www.wopr.com/w3tuserpics/Kevin_sig.gif alt="Keep the change, ya filthy animal...">
    <img src=/w3timages/blackline.gif width=33% height=2><img src=/w3timages/redline.gif width=33% height=2><img src=/w3timages/blackline.gif width=33% height=2>

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

    Re: Function Override Not Functioning (Word 2002)

    Kevin,

    I have managed to get confused. Can you explain the sequence of things that happen a bit more clearly.

    StuartR

  9. #9
    Gold Lounger
    Join Date
    Dec 2000
    Location
    Hollywood (sorta), California, USA
    Posts
    2,759
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Function Override Not Functioning (Word 2002)

    Sorry to bleed confusion all over your red cross vest...I'm grateful for your concern.

    Let me give this a try. Hang on to your hats, folks...

    We've got FileSave, FileSaveAs, FileClose, FileCloseAll and FileExit methods in a COM addin (formerly
    a VBA project global addin.)

    We've created DocumentBeforeClose and DocumentBeforeSave events, but the BeforeSave
    appears to be unnecessary (adds even more confusion) so we're got no code there right now.

    The idea is to process all exit paths through our code. If we see the dialog below, we have failed -- it
    means Word is bypassing our code and displaying its default dialog. That's bad. To differentiate, our
    dialog has a custom title, not Microsoft Word.

    The DocumentBeforeClose (let's call it DBC) event is the ONLY event trappable BEFORE Word's "Save document"
    prompt, so we've got to use it. Many MS MVPs direct you to the App_quit event for this sort of thing, but that
    event only fires AFTER all Word "Save document" prompts are completed --absolutely no help at all.

    As of this post I have discovered that DBC does not fire for each open, dirty document. It fires only for
    the first if more than 1 are open. This means that the code below will process only the first open doc
    through our FileClose method (this is C# code, but it's still relevant to the entire issue of taming
    Word's app events; the vb.net code is almost identical):
    private void wordApp_DocumentBeforeClose(Word.Document doc, ref bool cancel)
    {
    if (!doc.Saved)
    if (Dialog.FileClose() == "Cancel"
    cancel = true;
    }
    This says: If the document passed in by Word is not saved, call our FileClose method. Our FileClose
    provides the "Save Document" prompt and other processing if the user wants to save. If the user cancels,
    FileClose returns "Cancel" the DBC sets cancel = true to stop the whole show. If the user says No, we return
    to DBC and LET IT close the document by completing w/o the cancel=true.

    Now, the problem is DBC will only process the first document if there are more than 1 open! And when DBC ends
    Word displays the dialog below for the other open documents. The other problem is our FileClose method will
    close a document under certain circumstances; if DBC thinks it is supposed to close the same doc, we get a Word
    crash.

    The big breakthrough came when I decided to use DBC as the catch-all for capturing the exits and closes, but to
    manage the multiple docs myself with a loop. The above method now looks like this:
    private void wordApp_DocumentBeforeClose(Word.Document doc, ref bool cancel)
    {
    foreach (Word.Document oDoc in wordApp.Documents)
    {
    if (!oDoc.Saved)
    if (Dialog.FileClose(oDoc) == "Cancel"
    cancel = true;
    }
    }

    Notice that I now control which document is closing with the foreach. Also -- and this is big --
    I completely ignore the doc that Word passes into DBC! I loop on the Word documents collection
    and pass each one into FileClose.

    So far, seems to do the trick. If you've read this far, you're either bored to tears or even more
    confused, right? Sorry. But if there's an easier way, lay it out there, please. <img src=/S/dizzy.gif border=0 alt=dizzy width=15 height=15>
    Kevin <IMG SRC=http://www.wopr.com/w3tuserpics/Kevin_sig.gif alt="Keep the change, ya filthy animal...">
    <img src=/w3timages/blackline.gif width=33% height=2><img src=/w3timages/redline.gif width=33% height=2><img src=/w3timages/blackline.gif width=33% height=2>

  10. #10
    Gold Lounger
    Join Date
    Dec 2000
    Location
    Hollywood (sorta), California, USA
    Posts
    2,759
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Function Override Not Functioning (Word 2002)

    The show isn't over yet. There's still no differentiating between a Big X
    and a doc X close in the code posted...
    Kevin <IMG SRC=http://www.wopr.com/w3tuserpics/Kevin_sig.gif alt="Keep the change, ya filthy animal...">
    <img src=/w3timages/blackline.gif width=33% height=2><img src=/w3timages/redline.gif width=33% height=2><img src=/w3timages/blackline.gif width=33% height=2>

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

    Re: Function Override Not Functioning (Word 2002)

    Thanks for the clarification, now I understand - but I can't help much.

    If I get some time later in the week then I'll try playing with it to see if I can come up with a suggestion, but don't hold your breath.

    StuartR

  12. #12
    Gold Lounger
    Join Date
    Dec 2000
    Location
    Hollywood (sorta), California, USA
    Posts
    2,759
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Function Override Not Functioning (Word 2002)

    Thanks for any effort you are inclinded to expend on my behalf.

    It's ugly, though, I don't blame you if you don't get to it.
    Kevin <IMG SRC=http://www.wopr.com/w3tuserpics/Kevin_sig.gif alt="Keep the change, ya filthy animal...">
    <img src=/w3timages/blackline.gif width=33% height=2><img src=/w3timages/redline.gif width=33% height=2><img src=/w3timages/blackline.gif width=33% height=2>

  13. #13
    Uranium Lounger
    Join Date
    Dec 2000
    Location
    Los Angeles Area, California, USA
    Posts
    7,453
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Function Override Not Functioning (Word 2002)

    Hi Kevin:
    I got over here by accident <img src=/S/laugh.gif border=0 alt=laugh width=15 height=15>, but have you also looked at the commands
    DocClose
    FileClose
    FileCloseOrExit
    FileExit

    especially the 3rd one?
    Cheers,

  14. #14
    Gold Lounger
    Join Date
    Dec 2000
    Location
    Hollywood (sorta), California, USA
    Posts
    2,759
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Function Override Not Functioning (Word 2002)

    Phil,
    Thanks for accidentally dropping by. Yes, I am aware of all these "event subs". We trap some of them, but the problem re: closing Word with the BigX and closing documents with the docX still remains. Some day, I should write the treatise on this issue. What I have concluded after a long process of testing everything MS Word has to offer is that if a programmer wants to trap every possible way to save & close documents while Word is closing, the programmer *MUST* disable the BigX (application close). The reason for this is that both the BigX and the docX take you to the DocumentBeforeClose event, but there is not way your code can tell which one brought control into that app event. And it is very important that you know this information. Maybe there is a way using C++, but I cannot find any API call, VBA or .Net code that will tell me "hey, your user just clicked the application close X" (as opposed to the docX button).

    In lieu of the disabled BigX, I put up an alternative Application Close X on my app toolbar which is positioned upper right. Now I can manage the application close "event" and properly suggest file save locations for any and all open, dirty documents.

    Most coders are not doing what I'm doing: complete control of Word's save and close event code, so this "revelation" is no remedy for a slow news day in the forum. However, if I had encountered this knowledge a year ago (years ago?) I could have saved myself a whole lotta trouble...
    Kevin <IMG SRC=http://www.wopr.com/w3tuserpics/Kevin_sig.gif alt="Keep the change, ya filthy animal...">
    <img src=/w3timages/blackline.gif width=33% height=2><img src=/w3timages/redline.gif width=33% height=2><img src=/w3timages/blackline.gif width=33% height=2>

Posting Permissions

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