G
Guest
I'm trying to send email from a VB6 program via a COM Add-In. I've created a
simple Add In along the lines in Thomas Rizzo's book Programming Microsoft
Outlook... Chapter 7. I've added a Public Function SendEmail.
But I can't call my SendEmail function from another application. If anyone
has experience of calling functions in Add Ins from another application,
please let me know how you did it!
I created a VB6 project with a form and button Command1:
Private Sub Command1_Click()
Dim objOutlook As Outlook.Application
Dim objAddIn As Object
Dim MyAddIn As Object
Set objOutlook = Outlook.Application
On Error Resume Next
Set objAddIn = objOutlook.COMAddIns("MyCOMAddIn.Connect")
If Err.Number = 0 Then
'This will fail with Object doesn't support this property or method.
'objAddIn.SendMail "(e-mail address removed)", "Test Subject", "Test Message"
'So try the method shown in Rizzo's book
Set MyAddIn = GetObject("", "MyCOMAddIn.Connect")
'This won't work, because the oHostApp variable in MyAddIn is nothing.
MyAddIn.SendMail "(e-mail address removed)", "Test Subject", "Test Message"
End If
Set objOutlook = Nothing
End Sub
I saw a discussion that suggested adding the line highlighted below to the
OnConnection event in the Add In, but this fails with Object doesn't support
this property or method. I tried this line with 'Set' at the start, this
makes no difference.
Private Sub IDTExtensibility2_OnConnection(ByVal Application As Object, _
ByVal ConnectMode As AddInDesignerObjects.ext_ConnectMode, _
ByVal AddInInst As Object, custom() As Variant)
Set oHostApp = Application
'Thought this might help...
'oHostApp.COMAddIns.Item("MyComAddIn.Connect").Object = Me
If (ConnectMode <> ext_cm_Startup) Then
Call IDTExtensibility2_OnStartupComplete(custom)
End If
End Sub
simple Add In along the lines in Thomas Rizzo's book Programming Microsoft
Outlook... Chapter 7. I've added a Public Function SendEmail.
But I can't call my SendEmail function from another application. If anyone
has experience of calling functions in Add Ins from another application,
please let me know how you did it!
I created a VB6 project with a form and button Command1:
Private Sub Command1_Click()
Dim objOutlook As Outlook.Application
Dim objAddIn As Object
Dim MyAddIn As Object
Set objOutlook = Outlook.Application
On Error Resume Next
Set objAddIn = objOutlook.COMAddIns("MyCOMAddIn.Connect")
If Err.Number = 0 Then
'This will fail with Object doesn't support this property or method.
'objAddIn.SendMail "(e-mail address removed)", "Test Subject", "Test Message"
'So try the method shown in Rizzo's book
Set MyAddIn = GetObject("", "MyCOMAddIn.Connect")
'This won't work, because the oHostApp variable in MyAddIn is nothing.
MyAddIn.SendMail "(e-mail address removed)", "Test Subject", "Test Message"
End If
Set objOutlook = Nothing
End Sub
I saw a discussion that suggested adding the line highlighted below to the
OnConnection event in the Add In, but this fails with Object doesn't support
this property or method. I tried this line with 'Set' at the start, this
makes no difference.
Private Sub IDTExtensibility2_OnConnection(ByVal Application As Object, _
ByVal ConnectMode As AddInDesignerObjects.ext_ConnectMode, _
ByVal AddInInst As Object, custom() As Variant)
Set oHostApp = Application
'Thought this might help...
'oHostApp.COMAddIns.Item("MyComAddIn.Connect").Object = Me
If (ConnectMode <> ext_cm_Startup) Then
Call IDTExtensibility2_OnStartupComplete(custom)
End If
End Sub