Outlook VBA .Send()( Error

  • Thread starter Thread starter Ivan Weiss
  • Start date Start date
I

Ivan Weiss

I am trying to send a test e-mail through my program using Outlook so
that I know my code works and I can submit office forms through e-mail
instead of paper. Here is my code:

Dim objOutlook As New Outlook.Application()
Dim objMail As MailItem =
objOutlook.CreateItem(OlItemType.olMailItem)

With objMail
.To = "(e-mail address removed)"
.Subject = "Testing"
.HTMLBody = "<HTML><HEAD></HEAD><BODY bgcolor = 'red'>" _
& "<font color = 'white'>Hello!</font>" _
& "</body></html>"
'.Display()
.Send()
End With

objMail = Nothing
objOutlook = Nothing

I have
Imports Microsoft.Office.Core
Imports Outlook
above my form class

However, the .Send() method returns the following error:

'Send' is ambiguous across the inherited interfaces 'Outlook._MailItem'
and 'Outlook.ItemEvents_10_Event'.

Does anyone know why I am getting this and how I can send my email
without the user having to click on send?
 
Hi Ivan,

If the articles that Jay has given haven't taken you all the way, you can
do
Dim objMail As _MailItem
which makes objMail explicitly take the type that has the Send method.

or keep objMail as it is and use
DirectCast (objMail, Outlook._MailItem).Send
which uses the correct type just for the Send.

Regards,
Fergus
 
Back
Top