• Setting Event Listeners in Word Add In (Word 2k/XP)

    Home » Forums » AskWoody support » Productivity software by function » Visual Basic for Applications » Setting Event Listeners in Word Add In (Word 2k/XP)

    Author
    Topic
    #407717

    In my project, I created a Word Add In to monitor events from Application and CommandButton objects. Before it works, I have to set the event listeners. At first, I tried to set the listeners in a AutoExec macro. It works if I manually load the add in from Word menu. But if I load the add in from a C++ program, the AutoExec is not called.

    Can any one tell me how event listeners are initialized in a Word add in except the AutoExec macro?

    Thanx

    Viewing 1 reply thread
    Author
    Replies
    • #855043

      Is it an ordinary template or a COM Add-in?

      In a COM Add-in, there is a way to set the “on load” behavior. In my Outlook add-in, I right-clicked my Designer to access the code pane and created:

      Private Sub AddinInstance_OnConnection(ByVal Application As Object, _
                  ByVal ConnectMode As AddInDesignerObjects.ext_ConnectMode, _
                  ByVal AddInInst As Object, custom() As Variant)
      ' set up event handler for new Inspectors
      Call HandleInspector
      End Sub
       
      Private Sub AddinInstance_OnDisconnection(ByVal RemoveMode As _
                  AddInDesignerObjects.ext_DisconnectMode, custom() As Variant)
      ' I don't know that anything needs to happen here
      End Sub

      Hope this helps.

      • #855049

        Unfortunately, this is a template. I cannot use the COM Add In because there are macros overriding Word built-in commands.

        • #855107

          if the template is not in the startupfolder of word (options.DefaultFilePath(wdStartupPath)) it won’t load automatically.
          either put it in the startup folder or use the add method of the addins object to load it.

        • #855108

          if the template is not in the startupfolder of word (options.DefaultFilePath(wdStartupPath)) it won’t load automatically.
          either put it in the startup folder or use the add method of the addins object to load it.

      • #855050

        Unfortunately, this is a template. I cannot use the COM Add In because there are macros overriding Word built-in commands.

    • #855044

      Is it an ordinary template or a COM Add-in?

      In a COM Add-in, there is a way to set the “on load” behavior. In my Outlook add-in, I right-clicked my Designer to access the code pane and created:

      Private Sub AddinInstance_OnConnection(ByVal Application As Object, _
                  ByVal ConnectMode As AddInDesignerObjects.ext_ConnectMode, _
                  ByVal AddInInst As Object, custom() As Variant)
      ' set up event handler for new Inspectors
      Call HandleInspector
      End Sub
       
      Private Sub AddinInstance_OnDisconnection(ByVal RemoveMode As _
                  AddInDesignerObjects.ext_DisconnectMode, custom() As Variant)
      ' I don't know that anything needs to happen here
      End Sub

      Hope this helps.

    Viewing 1 reply thread
    Reply To: Setting Event Listeners in Word Add In (Word 2k/XP)

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

    Your information: