Results 1 to 5 of 5
  1. #1
    3 Star Lounger
    Join Date
    Aug 2002
    Location
    Denmark
    Posts
    347
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Event that doesn't fire...?? (W2K, O2K UK pro)

    Hi,

    I've used an MS example from the W2K help files.

    It's the App_DocumentBeforeSave, but though registered at launch the event does not fire.
    Can somebody help me...??

    I keep getting the question: "Do you want to save changes to the document template?" after having saved the active document for the first time, but only at the first save.
    I have a customized toolbar that is attached to the activedocument's attachedtemplate and resets itself when documents based on the template are active.


    The code I've implemented to avoid the "question" before save is:

    class module: clsDocStatus

    Public WithEvents App As Word.Application

    Private Sub App_DocumentBeforeSave(ByVal Doc As Document, SaveAsUI As Boolean, Cancel As Boolean)
    Dim a As Integer
    Dim i As Integer

    With Application.Templates
    For i = 1 To .Count
    If .Item(i).Saved = False Then .Item(i).Saved = True
    Next
    End With

    Application.Templates("Normal.dot").Saved = True
    Application.Templates(IO_APPLICATION_NAME).Saved = True
    ActiveDocument.AttachedTemplate.Saved = True

    ' a = MsgBox("Do you really want to save the document?", vbYesNo)
    ' If a = vbNo Then Cancel = True

    End Sub


    By this I try to make sure that the ".saved" indicators are the last things set.

    In a centralised module, I have the following code:

    Dim X As New clsDocStatus

    Sub Register_Event_Handler()
    Set X.App = Word.Application
    End Sub

    ...and in the Autonew and Autoopen events...

    sub main
    Register_Event_Handler

    (bla, bla, bla)

    End sub


    For some reason the "App_DocumentBeforeSave" event doesn't seem to fire...

    Any good ideas ??
    Bests,
    RD


    PS: Wish there were a knob on the TV to turn up the intelligence. There's a knob called "brightness," but that doesn't work

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

    Re: Event that doesn't fire...?? (W2K, O2K UK pro)

    Have you verified that the event really doesn't fire, for example by setting a breakpoint in the code? It might be that the code runs, but that something else happens after it to set the template to "dirty" again.

  3. #3
    3 Star Lounger
    Join Date
    Aug 2002
    Location
    Denmark
    Posts
    347
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Event that doesn't fire...?? (W2K, O2K UK pro)

    yep
    Bests,
    RD


    PS: Wish there were a knob on the TV to turn up the intelligence. There's a knob called "brightness," but that doesn't work

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

    Re: Event that doesn't fire...?? (W2K, O2K UK pro)

    Hello Henrik,

    I created a template and put the code from your first post into it (class module, standard module, Document_Open and Document_New).

    I saved the template and created a document based on the template. I modified a style in the document and specified "Add to Template". I verified that the template was "dirty" after this (ActiveDocument.AttachedTemplate.Saved was True before modifying the style, and False after.) When I closed the document, I was only asked whether I wanted to save the document itself, the template was not saved. I also verified that the Document_BeforeSave procedure ran by inserting a Beep instruction.

    So the code itself seems to be OK, there must be something else intervening. Do you have other templates loaded that might trap application-level events?

  5. #5
    2 Star Lounger
    Join Date
    Feb 2001
    Location
    Brussels, Brussel, Belgium
    Posts
    159
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Event that doesn't fire...?? (W2K, O2K UK pro)

    hi Henrik,

    "I have a customized toolbar that is attached to the activedocument's attachedtemplate and resets itself when documents based on the template are active."

    could you explain this further?

    as i am interpreting it now, it seems to me you don't need to create a beforesave event at all, but your code that resets "itself"?? needs a customizationcontext to prevent other templates from getting dirty. this will prevent word from asking to save the template.

    'pseudocode:
    prevcc=customizationcontext
    customizationcontext=activedocument.attachedtempla te
    'your reset code
    activedocument.attachedtemplate.saved=true
    customizationcontext=prevcc

    as to why the event is not firing, try Hans' suggestions. also when you're debugging, public variables tend to reset easily. if you have an end statement or an unhandled error somewhere (might be another template or addin), public vars will be reset and you'll lose the event as well.

Posting Permissions

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