Results 1 to 6 of 6
  1. #1
    New Lounger
    Join Date
    Aug 2005
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts

    knowing if Word is quitting in DocumentChange (Wor

    I'm working on a small application that uses a custom COM object to handle an interface with Word, and I'm having some trouble with a particular part of the COM object. Essentially, the application loads up the COM object, and then waits until it receives an event from the COM object to tell it that we're done in Word.

    The problem is as follows:

    When a user closes a document, but not Word itself, we detect this via the DocumentChange event. If it is a document we care about, we send a message back to the application that is actually using our COM object, telling it that the document is closed.

    However, if the user closes Word itself, we want to tell the the application using our COM object that this has occurred, and it's important that this is distinguished from just closing a document.

    The problem is, DocumentChange fires before OnQuit, and as far as I can tell, there is no way to know from within DocumentChange that we are in fact quitting. So, I'm having trouble figuring out a good way to let the application using our object know this information. We send our message in DocumentChange, but the application we're sending messages back to has no way of knowing whether the other message (from OnQuit) is going to come.

    Any ideas? Thanks for any help you can give.

  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: knowing if Word is quitting in DocumentChange

    <P ID="edit" class=small>(Edited by jscher2000 on 22-Aug-05 22:17. )</P>My previous post wasn't very relevant. It sounds as though the Quit event really is the one to watch. Since you have all the plumbing in place for the DocumentChange event, it should be fairly straightforward to add an event handler for Quit.

    <UL>You may have chosen DocumentChange based on limitations or problems with Document_Close or DocumentBeforeClose but, if not, you might look into those. There also should be a Quit event to hook into. Some links:

    Using Events with the Document Object
    Take Control of Microsoft Word Through Events
    WD2000: Document_Close Event Runs Twice When Quitting Word
    WD2000: Document_Close Event and AutoClose Macro Fail When Closing Document
    [/list]

  3. #3
    New Lounger
    Join Date
    Aug 2005
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: knowing if Word is quitting in DocumentChange

    I'm not sure if I'm explaining it correctly, but the Quit event is not right for what I want to do. The reason for this is, the sequence that happens is:

    1. User tells Word to quit
    2. Word closes all documents, thus firing the DocumentChange event
    3. We see our document closing, but there is currently no indication if only the document is closing, or if Word is actually quitting
    4. We send an event telling our program that the document is closing
    5. Word fires the Quit method
    6. We send an event to our program telling it that Word has quit

    The problem here is that the program using the COM object has no way of knowing, at step 4, whether this is a Close, or a Close+Quit, and it's important to us to differentiate. So, I'm looking for some way to know that Word is quitting when we reach step 4, so that we can send a different message back, indicating that we are quitting, not just closing.

  4. #4
    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: knowing if Word is quitting in DocumentChange

    Oh, that's a bit harder. <img src=/S/grin.gif border=0 alt=grin width=15 height=15> Can you interrogate the "ActionControl" that the user used to start the process? We've had threads on this, but I don't remember whether it is accessible without a lot of rigmarole.

  5. #5
    New Lounger
    Join Date
    Aug 2005
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: knowing if Word is quitting in DocumentChange

    I'm not very familiar with the use of 'ActionControl', so after a little searching I tried taking a look at appWord.CommandBars.ActionControl. With a watch on it, I stepped through the process, and it appears to be 'Nothing' at all times. Any further hints?

    (searching for earlier discussions on this has not clarified the issue either)

  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: knowing if Word is quitting in DocumentChange

    Sorry, I don't know when it works and when it doesn't.

    Attached is something hastily converted over from an Outlook project to Word. It contains the following event handler code:

    Class1 module:
    <pre>Public WithEvents menuQuit As CommandBarButton

    Private Sub menuQuit_Click(ByVal Ctrl As Office.CommandBarButton, _
    CancelDefault As Boolean)
    MsgBox "Bing! User is closing Word."
    CancelDefault = False
    End Sub</pre>


    Module1 module:
    <pre>Dim cbEvent As New Class1

    Sub SetIntercept(intID As Integer)
    ' Event monitoring setup
    Dim ctlBtn As CommandBarButton
    Set ctlBtn = Word.Application.CommandBars.FindControl(ID:=intID )
    Set cbEvent.menuQuit = ctlBtn
    End Sub</pre>


    ThisDocument module:
    <pre>Private Sub Document_New()
    SetIntercept 752
    End Sub

    Private Sub Document_Open()
    SetIntercept 752
    End Sub</pre>


    I'll be curious where in the sequence of events this fires, and whether it helps. Unfortunately, it might not trap the "Red X" button (Window title bar close button). I can't recall whether anyone has posted code for that.
    Attached Files Attached Files

Posting Permissions

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