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

    Home » Forums » AskWoody support » Productivity software by function » Visual Basic for Applications » Intercepting Word document events from an addin (Word 2002 SP 2)

    Author
    Topic
    #407306

    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. dizzy

    Viewing 1 reply thread
    Author
    Replies
    • #850868

      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.

    • #850869

      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.

    Viewing 1 reply thread
    Reply To: Intercepting Word document events from an addin (Word 2002 SP 2)

    You can use BBCodes to format your content.
    Your account can't use all available BBCodes, they will be stripped before saving.

    Your information: