Results 1 to 3 of 3
  1. #1
    2 Star Lounger
    Join Date
    Jun 2002
    Location
    vancouver, BC, Br. Columbia
    Posts
    109
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Intercepting Word document events from an addin (Word 2002 SP 2)

    I have a sub called "Autoclose" in the ThisDocument object and also, in desperation, a class module (my first "WithEvents" class) with a DocumentBeforeClose event. They both work when I open a document based on a .dot template, but neither work when I make the .dot template an addin. This is what I need because I need to intercept every time the user closes a document.

    In the ThisDocument object:
    Sub autoclose()
    MsgBox "autoclose"
    End Sub

    In the class module:
    Public WithEvents App As Application
    Private Sub App_DocumentBeforeClose(ByVal Doc As Document, Cancel As Boolean)
    MsgBox "before close event"
    End Sub

    Of course with the before close event I can understand why it's not working ... because I need some way to instantiate an object variable that points to the application object and listens for events. The only place I can think of to do this is with AutoNew and AutoOpen, but just like AutoClose, these don't fire when the template is loaded as an Addin. <sigh> <img src=/S/dizzy.gif border=0 alt=dizzy width=15 height=15>

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

    Re: Intercepting Word document events from an addin (Word 2002 SP 2)

    According to WD2000: Auto Macros in Word (I assume it's the same for Word 2002), AutoExec and AutoExit run in add-ins, but AutoNew, AutoOpen and AutoClose don't. So initialize the application variable in the AutoExec macro.

  3. #3
    2 Star Lounger
    Join Date
    Jun 2002
    Location
    vancouver, BC, Br. Columbia
    Posts
    109
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Intercepting Word document events from an addin (Word 2002 SP 2)

    Hans - Thank you! Works like a beauty now. <img src=/S/cloud9.gif border=0 alt=cloud9 width=25 height=23>

Posting Permissions

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