Results 1 to 6 of 6
  1. #1
    New Lounger
    Join Date
    Apr 2004
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Outlook COM ADD IN (Office XP VBA6)

    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

  2. #2
    Super Moderator jscher2000's Avatar
    Join Date
    Feb 2001
    Location
    Silicon Valley, USA
    Posts
    23,112
    Thanks
    5
    Thanked 93 Times in 89 Posts

    Re: Outlook COM ADD IN (Office XP VBA6)

    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. <img src=/S/smile.gif border=0 alt=smile width=15 height=15> 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

    <pre>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</pre>

    Class module named clsOL01

    <pre>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</pre>

    Regular code module named OL01

    <pre>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:=int ID)
    Set OLEvents.InsFile = ctlBtn
    End Sub

    Function AttachWDXFiles() As Boolean
    ...details omitted...
    End Function
    </pre>

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

  3. #3
    Gold Lounger
    Join Date
    Dec 2000
    Location
    New Hampshire, USA
    Posts
    3,386
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Outlook COM ADD IN (Office XP VBA6)

    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.

  4. #4
    Gold Lounger
    Join Date
    Dec 2000
    Location
    New Hampshire, USA
    Posts
    3,386
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Outlook COM ADD IN (Office XP VBA6)

    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.

  5. #5
    New Lounger
    Join Date
    Apr 2004
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Outlook COM ADD IN (Office XP VBA6)

    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.

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

    Re: Outlook COM ADD IN (Office XP VBA6)

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

Posting Permissions

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