Calling Outlook VBA Macro from outside (VB/VBScript/C#)

It seems to be insignificant but it might turn out to be useful some times.
Consider a situation where you have a VBA Macro in outlook (any office application for that matter) the name of the subroutine is SendCustomEmail and you want it to call from outside the outlook (it should be running or you can make it run).

The sample code to call SendCustomEmail here is in vbscript.

set app= createobject("Outlook.Application")
call app.SendCustomEmail(" test@mydomain.com ")

You will have to write subroutine SendCustomEmail with a parameter in outlook macro.

It is easy in VBScript or VB for that matter as we can directly make use of the late binding.

In case of .Net here in C#

<CODE BLOCK>

Type mtype;
Microsoft.Office.Interop.Outlook.Application outlook;
outlook = new Microsoft.Office.Interop.Outlook.ApplicationClass();
mtype = outlook.GetType();
string[] strArr;
strArr = new string[1];
strArr[0] = "
test@mydomain.com ";
mtype.InvokeMember("SendCustomEmail",System.Reflection.BindingFlags.InvokeMethod,null,outlook,strArr);

</CODE BLOCK>

Similarly we can also call Macro written in word, excel etc.

Hope this turn up to be useful some where.

-Sachin Sancheti
An obstacle is what we see when we take our eyes off the goal.