![]() |
If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below. |
|
|
Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
![]()
I am using Delphi (2009) to write my first add-in for Outlook (2007). I want to add a custom method to my add-in's class and call it from an Outlook macro, but I can't get it working.
My method in my Delphi class is public. It looks like this: procedure MyMethod(const Index : integer); safecall; I tried to call it from Outlook like this: Sub Test_02() Application.COMAddIns.Item("My Add In").Object.MyMethod (3) End Sub I get: Run-time error '91': Object variable or With block variable not set I then tried: Sub Test_01() Dim MyAddIn As Office.COMAddIn Set MyAddIn = Application.COMAddIns.Item("My Add In") If Not (MyAddIn Is Nothing) Then If MyAddIn.Connect = True Then Dim MyObject As Object Set MyObject = MyAddIn.Object If Not (MyObject Is Nothing) Then MyObject.MyMethod (3) End If End If End If End Sub This fails because MyObject is Nothing, so the call to MyObject.MyMethod doesn't happen. My next attempt was: Sub Test_03() Dim MyObject As Object Set MyObject = CreateObject("My Add In") If Not (MyObject Is Nothing) Then MyObject.DoNewMail (Null) End If End Sub The DoNewMail method is the handler for Outlooks OnNewMail event, and is called correctly when new mail is received. I guess CreateObject would create a new object rather than use the one already instantiated in my Add-In, which is not what I want, but I was trying everything at this stage. Anyway, this attempt failed with: Run-time error '438': Object doesn't support this property or method So where am I going wrong? |
#2
|
|||
|
|||
![]()
After being stuck on this for days I hit on a solution.
In my OnConnection event in the Delphi code I put something like: var SelfDisp : OleVariant; begin SelfDisp := Self as IMyClassDisp; OleVariant(AddInInst).Object := SelfDisp; (IMyClassDisp is a descendant of IDispatch). Then the IMyClassDisp methods included in the type library can be called from a macro using the same syntax I had tried earlier. Just thought I would post this note in case anyone else finds this thread whilst stuck on the same problem. |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Thread Starter | Forum | Replies | Last Post |
Custom VBA forms in Outlook--how to call w/macro? | Sharon Wright | Outlook - Using Forms | 1 | June 9th 09 06:46 PM |
Call AddIn-Functions from VBA-Macro | Steffen Grellmann[_2_] | Add-ins for Outlook | 7 | July 23rd 08 09:34 PM |
How do I call a VBA macro to process every incoming message? | rob | Outlook and VBA | 2 | February 28th 08 03:01 PM |
Call macro from userdefined Ribbon | Steffen Grellmann | Add-ins for Outlook | 5 | March 22nd 07 01:18 PM |
Call macro stored in Excel workbook from Outlook's macro | Gvaram | Outlook and VBA | 5 | October 4th 06 06:26 AM |