Hi,
Here goes the code snippet.
1. Modify the attribute of the Connect ,add the Hello test funtion, so that
the com client, i.e. the VBA can see the function by using COM interface.
[GuidAttribute("E661AF83-1B16-4983-A64C-5E5FEDC0C4FC"),
ProgId("WordAddin.Connect"),ClassInterface(ClassInterfaceType.AutoDual),ComV
isible(true)]
public class Connect : Object, Extensibility.IDTExtensibility2
public void OnConnection(object application,
Extensibility.ext_ConnectMode connectMode, object addInInst, ref
System.Array custom)
{
applicationObject = application;
addInInstance = addInInst;
((Microsoft.Office.Core.COMAddIn)addInInst).Object = this;
}
public void Hello(string str)
{
System.Windows.Forms.MessageBox.Show(str);
}
2. in the VBA editor(i.e. word visual basic editor add a reference to the
com addin's tlb file.
3. Now we can call the Hello in the word macro.
e.g.
Sub Test()
Dim o As Object
Set o = Application.COMAddIns.Item("WordAddin.Connect").Object
o.Hello "df"
End Sub
In this way, the macro test will call the method hello in the addin
Best regards,
Peter Huang
Microsoft Online Partner Support
Get Secure! -
www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.