A Microsoft Outlook email forum. Outlook Banter

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.

Go Back   Home » Outlook Banter forum » Microsoft Outlook Email Newsgroups » Add-ins for Outlook
Site Map Home Register Authors List Search Today's Posts Mark Forums Read Web Partners

Call add-in method from macro?



 
 
Thread Tools Search this Thread Display Modes
  #1  
Old November 17th 09, 07:23 AM posted to microsoft.public.outlook.program_addins
Duncan McNiven
external usenet poster
 
Posts: 2
Default Call add-in method from macro?

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  
Old November 17th 09, 06:10 PM posted to microsoft.public.outlook.program_addins
Duncan McNiven
external usenet poster
 
Posts: 2
Default Call add-in method from macro? SOLVED

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
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
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


All times are GMT +1. The time now is 08:24 AM.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.Search Engine Friendly URLs by vBSEO 2.4.0
Copyright ©2004-2025 Outlook Banter.
The comments are property of their posters.