• Outlook COM ADD IN (Office XP VBA6)

    Author
    Topic
    #403498

    Hi. I have a simple macro that works fine in VBA within Outlook – I store it in VBAProject.OTM. The problem is, when I distribute this, end-users must set the security to LOW. I also have to override menu items by modifying outcmd.dat.
    The solution is for me to create a COM AddIn, which I am doing with VBA6.
    I have code samples from Professional Outlook 200 Programming (Slovak, Burhham, Gifford). The dll works perfectly – It adds menu items and buttons.
    When I run this EXACT CODE in Outlook VBA, the menu and buttons are created AND they also run the simple macros. But once in the DLL, the buttons do not run the macros. I’ve even stripped down the macro to just a msgbox with still no luck. It’s as if the DLL has shut down after its initial run. (It runs on Outlook start up, because I can get the menus to add, and even the test sub msgbox macro to run.) Could this be a security issue? But then why would it be allowed to run on startup but then fail?
    THANKS,
    MARCIO SERRAO

    Viewing 3 reply threads
    Author
    Replies
    • #812750

      My only COM Add-in is designed to listen for the ID associated with the Insert>File command inside a message composition window. Thus, I haven’t had to create any commandbar controls.

      What is your code to intercept the button presses? Mine is more or less as follows; I certainly do not claim that this is efficient, it was my first COM Add-in, my first event-handling project, and had to be done in my spare time in a matter of days. smile And now that it works, I haven’t had much incentive to tinker with it. So, for what it’s worth:

      Add-in Designer named WDX_OL

      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

      Class module named clsOL01

      Public WithEvents NewInsp As Outlook.Inspectors
      Public WithEvents ActiveInsp As Outlook.Inspector
      Public WithEvents InsFile As CommandBarButton
       
      Private Sub NewInsp_NewInspector(ByVal Inspector As Inspector)
      'main routine to re-route the button click
      'only want to handle messages...
      If Inspector.CurrentItem.Class  olMail Then Exit Sub
      'initialize event handler class for this message
      Call SetIntercept(Inspector, 1079)
      End Sub
       
      Private Sub ActiveInsp_Activate()
      'not sure if this runs, but just as a backup
      'only want to handle messages...
      If ActiveInspector.CurrentItem.Class  olMail Then Exit Sub
      'initialize event handler class for this message
      Call SetIntercept(ActiveInspector, 1079)
      End Sub
       
      Private Sub InsFile_Click(ByVal Ctrl As Office.CommandBarButton, _
                                CancelDefault As Boolean)
      If AttachWDXFiles Then  'cancel the default Insert File dialog
          CancelDefault = True
      Else
          CancelDefault = False
      End If
      End Sub

      Regular code module named OL01

      Dim OLEvents As New clsOL01
      Sub HandleInspector()
      'initialize event handler for a new inspector (mail or otherwise)
      Set OLEvents.NewInsp = Outlook.Inspectors           'when new insp created
      Set OLEvents.ActiveInsp = Outlook.ActiveInspector   'when insp activated
      End Sub
       
      Sub SetIntercept(myInsp As Inspector, intID As Integer)
      Dim ctlBtn As CommandBarButton
      Set ctlBtn = myInsp.CommandBars("Standard").FindControl(Id:=intID)
      Set OLEvents.InsFile = ctlBtn
      End Sub
       
      Function AttachWDXFiles() As Boolean
      ...details omitted...
      End Function
      

      Too bad it doesn’t work for users who use Word as their mail editor….. Hope this helps.

    • #812751

      My only COM Add-in is designed to listen for the ID associated with the Insert>File command inside a message composition window. Thus, I haven’t had to create any commandbar controls.

      What is your code to intercept the button presses? Mine is more or less as follows; I certainly do not claim that this is efficient, it was my first COM Add-in, my first event-handling project, and had to be done in my spare time in a matter of days. smile And now that it works, I haven’t had much incentive to tinker with it. So, for what it’s worth:

      Add-in Designer named WDX_OL

      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

      Class module named clsOL01

      Public WithEvents NewInsp As Outlook.Inspectors
      Public WithEvents ActiveInsp As Outlook.Inspector
      Public WithEvents InsFile As CommandBarButton
       
      Private Sub NewInsp_NewInspector(ByVal Inspector As Inspector)
      'main routine to re-route the button click
      'only want to handle messages...
      If Inspector.CurrentItem.Class  olMail Then Exit Sub
      'initialize event handler class for this message
      Call SetIntercept(Inspector, 1079)
      End Sub
       
      Private Sub ActiveInsp_Activate()
      'not sure if this runs, but just as a backup
      'only want to handle messages...
      If ActiveInspector.CurrentItem.Class  olMail Then Exit Sub
      'initialize event handler class for this message
      Call SetIntercept(ActiveInspector, 1079)
      End Sub
       
      Private Sub InsFile_Click(ByVal Ctrl As Office.CommandBarButton, _
                                CancelDefault As Boolean)
      If AttachWDXFiles Then  'cancel the default Insert File dialog
          CancelDefault = True
      Else
          CancelDefault = False
      End If
      End Sub

      Regular code module named OL01

      Dim OLEvents As New clsOL01
      Sub HandleInspector()
      'initialize event handler for a new inspector (mail or otherwise)
      Set OLEvents.NewInsp = Outlook.Inspectors           'when new insp created
      Set OLEvents.ActiveInsp = Outlook.ActiveInspector   'when insp activated
      End Sub
       
      Sub SetIntercept(myInsp As Inspector, intID As Integer)
      Dim ctlBtn As CommandBarButton
      Set ctlBtn = myInsp.CommandBars("Standard").FindControl(Id:=intID)
      Set OLEvents.InsFile = ctlBtn
      End Sub
       
      Function AttachWDXFiles() As Boolean
      ...details omitted...
      End Function
      

      Too bad it doesn’t work for users who use Word as their mail editor….. Hope this helps.

    • #812825

      The best two Outlook programming books are likely:

      Sue Mosher’s Microsoft Outlook Programming (ISBN: 1-55558-286-9)
      Randy Byrne’s Building Applications wit hMicrosoft Outlook version 2002(ISBN: 0-7356-1273-0). There was also an edition for version 2000.

      Both cover COM add-ins for Outlook.

      • #812827

        I just looked at the two books.

        Randy Byrne’s book does have a significant chapter on COM Add-ins.

        Sue Mosher’s book does not have much on COM Add-ins.

        • #813209

          Thanks. I just ordered Randy Byrne’s book from Amazon.

          From a bit more looking around, I’ve found out that I need to use WITHEVENTS to catch the button click. I’ve found some sample code, but all of them bomb on some line or another. Even the built in code in the DESIGNER of VB6 doesn’t work in Outlook. Ugh.
          Thanks.

          • #850866

            I just bought the book too – they should be paying a royalty to woody

          • #850867

            I just bought the book too – they should be paying a royalty to woody

        • #813210

          Thanks. I just ordered Randy Byrne’s book from Amazon.

          From a bit more looking around, I’ve found out that I need to use WITHEVENTS to catch the button click. I’ve found some sample code, but all of them bomb on some line or another. Even the built in code in the DESIGNER of VB6 doesn’t work in Outlook. Ugh.
          Thanks.

      • #812828

        I just looked at the two books.

        Randy Byrne’s book does have a significant chapter on COM Add-ins.

        Sue Mosher’s book does not have much on COM Add-ins.

    • #812826

      The best two Outlook programming books are likely:

      Sue Mosher’s Microsoft Outlook Programming (ISBN: 1-55558-286-9)
      Randy Byrne’s Building Applications wit hMicrosoft Outlook version 2002(ISBN: 0-7356-1273-0). There was also an edition for version 2000.

      Both cover COM add-ins for Outlook.

    Viewing 3 reply threads
    Reply To: Outlook COM ADD IN (Office XP VBA6)

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

    Your information: