none
Enabling a COM Add-in via VBA on Outlook Startup. RRS feed

  • Question

  • We have an issue with a pesky COM Add-in that keeps disabling.  We are aware we need a "big picture" fix and working towards a formal solution, but I have been tasked with writing some VBA code that will run when Outlook starts to verify if the add-in is enabled and if not, enable it.  Unfortunately, my coding skills are pretty rough.  Having said that, this is what I have so far and it does nothing but raise my blood pressure.

    Any insights would be greatly appreciated!

    Thanks in advance.

    Sub test2()
    Dim MyAddin As Office.COMAddIn
    Set MyAddin = Application.COMAddIns.Item("xxxxxxxxxx.OutlookAddin.1")
    MyAddin.Connect = True
    End Sub

    Thursday, January 19, 2012 10:12 PM

Answers

  • If an addin is being unloaded due to some error, just connecting it won't solve the problem. It will just get disconnected and unloaded again as soon as you enable it by setting Connected = true. To fix the problem you need to fix the underlying problem of something missing such as a dependency or requirement, or some load error, or some unhandled exception.
     
    All of those things may unload an addin or even disable it. If it's disabled you must re-enable it before it will run at all.

    --
    Ken Slovak
    MVP - Outlook
    http://www.slovaktech.com
    Author: Professional Programming Outlook 2007
     
     
    "Cabin Guy" <=?utf-8?B?Q2FiaW4gR3V5?=> wrote in message news:12770619-852f-4838-9eed-961920620b6b...

    Question:  Should I expect the checkbox in the Com Add-ins interface to be enabled after running this script, because so far it does not seeem to be working, though I do not recieve any particular error message.


    Ken Slovak MVP - Outlook
    Friday, January 20, 2012 4:53 PM
    Moderator
  • If an addin is actually disabled you can re-enable it from the UI, or by deleting a registry key when Outlook isn't running. So you could delete the key using VBA code, but it would have to be when Outlook isn't running or you need to exit and restart Outlook after the code runs.
     
    Be aware though that if Outlook is disabling the addin it will continue to do so until the problem is fixed. So no matter what workarounds you try it will continue to become disabled as soon as the flaw is exposed, whatever that is.

    --
    Ken Slovak
    MVP - Outlook
    http://www.slovaktech.com
    Author: Professional Programming Outlook 2007
     
     
    "Cabin Guy" <=?utf-8?B?Q2FiaW4gR3V5?=> wrote in message news:c7b4a653-86da-4e8e-ad7e-4791f0b40bcd...
    Thanks Ken.  We are working on the big picture fix as we speak.  Is there a way to re-enable the Add-in using VBA?

    Ken Slovak MVP - Outlook
    Friday, January 20, 2012 5:09 PM
    Moderator
  • Sorry, typo:

    For intX = 1To Application.COMAddIns.Count

    FYI, you can use a string for the index:

    COMAddIn Object:
    http://msdn.microsoft.com/en-us/library/aa831759(office.10).aspx


    Eric Legault
    MVP (Outlook)
    About me...
    Thursday, January 19, 2012 11:04 PM
    Moderator

All replies

  • I can't recall if you can use the add-in name as an indexer for the Item method.  Try looping through the collection instead:

            Dim intX As Integer
            For intX As = 1 To Application.COMAddIns.Count
                Dim objAddIn As Object 'Try COMAddIn if you have a reference set to the Office type library
    
                Set objAddIn = Application.COMAddIns.Item(intX)
    
                If objAddIn.ProgId = "MyAddin" Then
                    If objAddIn.Connect = False Then            
                        objAddIn.Connect = True                    
                    End If
                End If
                
                Set objAddIn = Nothing
            Next
    


    Eric Legault
    MVP (Outlook)
    About me...
    Thursday, January 19, 2012 10:41 PM
    Moderator
  • Thanks Eric.

    I am getting a syntax error on the second line.

    For intX As = 1 To Application.COMAddIns.Count

    BTW - Outlook 10.

    Thursday, January 19, 2012 10:53 PM
  • Sorry, typo:

    For intX = 1To Application.COMAddIns.Count

    FYI, you can use a string for the index:

    COMAddIn Object:
    http://msdn.microsoft.com/en-us/library/aa831759(office.10).aspx


    Eric Legault
    MVP (Outlook)
    About me...
    Thursday, January 19, 2012 11:04 PM
    Moderator
  • Thanks again!

    Friday, January 20, 2012 4:37 PM
  • Question:  Should I expect the checkbox in the Com Add-ins interface to be enabled after running this script, because so far it does not seeem to be working, though I do not recieve any particular error message.

    Friday, January 20, 2012 4:45 PM
  • If an addin is being unloaded due to some error, just connecting it won't solve the problem. It will just get disconnected and unloaded again as soon as you enable it by setting Connected = true. To fix the problem you need to fix the underlying problem of something missing such as a dependency or requirement, or some load error, or some unhandled exception.
     
    All of those things may unload an addin or even disable it. If it's disabled you must re-enable it before it will run at all.

    --
    Ken Slovak
    MVP - Outlook
    http://www.slovaktech.com
    Author: Professional Programming Outlook 2007
     
     
    "Cabin Guy" <=?utf-8?B?Q2FiaW4gR3V5?=> wrote in message news:12770619-852f-4838-9eed-961920620b6b...

    Question:  Should I expect the checkbox in the Com Add-ins interface to be enabled after running this script, because so far it does not seeem to be working, though I do not recieve any particular error message.


    Ken Slovak MVP - Outlook
    Friday, January 20, 2012 4:53 PM
    Moderator
  • Thanks Ken.  We are working on the big picture fix as we speak.  Is there a way to re-enable the Add-in using VBA?
    Friday, January 20, 2012 4:59 PM
  • BTW - Allow me to explain.

    There is a bug in one third-party COM Add-in that will disable itself and freeze Outlook if the end user attempts to forward an email with an attachment when the attachment is open for editing.  The vendor is working on a fix for this bug, but in the mean time we need make sure that the add-in does not disable itself and stay disabled.  The Add-in is a security tool that must run on each and every email before it is sent and if it is disabled then obviously it will not function.  Just because the user "breaks" the Add-in by not closing a particular document prior to sending does not mean it should not continue to function on the remaining emails the user works with upon relaunch. I hope that makes sense.  Please let me know if you have any questions.

    Thanks again!

    Friday, January 20, 2012 5:08 PM
  • If an addin is actually disabled you can re-enable it from the UI, or by deleting a registry key when Outlook isn't running. So you could delete the key using VBA code, but it would have to be when Outlook isn't running or you need to exit and restart Outlook after the code runs.
     
    Be aware though that if Outlook is disabling the addin it will continue to do so until the problem is fixed. So no matter what workarounds you try it will continue to become disabled as soon as the flaw is exposed, whatever that is.

    --
    Ken Slovak
    MVP - Outlook
    http://www.slovaktech.com
    Author: Professional Programming Outlook 2007
     
     
    "Cabin Guy" <=?utf-8?B?Q2FiaW4gR3V5?=> wrote in message news:c7b4a653-86da-4e8e-ad7e-4791f0b40bcd...
    Thanks Ken.  We are working on the big picture fix as we speak.  Is there a way to re-enable the Add-in using VBA?

    Ken Slovak MVP - Outlook
    Friday, January 20, 2012 5:09 PM
    Moderator
  • Ken,

    I totally understand what you are saying and agree 100%, but we have over 1,000 users, most of which have no idea how to enable/disable Com Addins, which is why I have been directed to create this script to insure that when Outlook is launched the add-in is enabled.  The program actually freezes and HAS to restart when the user falls into the trap, which is really the one thing going for us.  The user is forced to restart the program and this is our chance to fix the isssue, if even temporary.  We are aware that a bigger fix is needed, but this is to act as a temporary patch.

    Having said that, is there a way to check on start up to make sure the Addin is enabled and if not enable it (and if it is already enabled then just exit)?

    Friday, January 20, 2012 5:16 PM
  • To see if an addin is disabled you check it's Connect property. True means it's connected and false means it's not.

    --
    Ken Slovak
    MVP - Outlook
    http://www.slovaktech.com
    Author: Professional Programming Outlook 2007
     
     
    "Cabin Guy" <=?utf-8?B?Q2FiaW4gR3V5?=> wrote in message news:1cabcee6-3cbe-4171-91b6-bf5a6b140e93...

    Ken,

    I totally understand what you are saying and agree 100%, but we have over 1,000 users, most of which have no idea how to enable/disable Com Addins, which is why I have been directed to create this script to insure that when Outlook is launched the add-in is enabled.  The program actually freezes and HAS to restart when the user falls into the trap, which is really the one thing going for us.  The user is forced to restart the program and this is our chance to fix the isssue, if even temporary.  We are aware that a bigger fix is needed, but this is to act as a temporary patch.

    Having said that, is there a way to check on start up to make sure the Addin is enabled and if not enable it (and if it is already enabled then just exit)?


    Ken Slovak MVP - Outlook
    Friday, January 20, 2012 6:18 PM
    Moderator