N
Nicole
I found this code below to use to send emails using VB with Outlook.
However, it gives these errors.
'Send' is ambiguous across the inherited interfaces 'Outlook._MailItem' and
'Outlook.ItemEvents_Event'.
Name 'olByReference' is not declared.
Name 'olMailItem' is not declared.
Name 'olTo' is not declared.
How could i edit this code to get it to work?
Any suggestions would be greatly appreciated!!
Nicole
Sub NewMailMessage()
Dim ol As New Outlook.Application
Dim ns As Outlook.NameSpace
Dim newMail As Outlook.MailItem
'Return a reference to the MAPI layer.
Set ns = ol.GetNamespace("MAPI")
'Create a new mail message item.
Set newMail = ol.CreateItem(olMailItem)
With newMail
'Add the subject of the mail message.
.Subject = "Test"
'Create some body text.
.Body = "Test"
'Add a recipient and test to make sure that the
'address is valid using the Resolve method.
With .Recipients.Add("(e-mail address removed)")
.Type = olTo
If Not .Resolve Then
MsgBox "Unable to resolve address.", vbInformation
Exit Sub
End If
End With
'Send the mail message.
.Send
End With
'Release memory.
Set ol = Nothing
Set ns = Nothing
Set newMail = Nothing
End Sub
However, it gives these errors.
'Send' is ambiguous across the inherited interfaces 'Outlook._MailItem' and
'Outlook.ItemEvents_Event'.
Name 'olByReference' is not declared.
Name 'olMailItem' is not declared.
Name 'olTo' is not declared.
How could i edit this code to get it to work?
Any suggestions would be greatly appreciated!!
Nicole
Sub NewMailMessage()
Dim ol As New Outlook.Application
Dim ns As Outlook.NameSpace
Dim newMail As Outlook.MailItem
'Return a reference to the MAPI layer.
Set ns = ol.GetNamespace("MAPI")
'Create a new mail message item.
Set newMail = ol.CreateItem(olMailItem)
With newMail
'Add the subject of the mail message.
.Subject = "Test"
'Create some body text.
.Body = "Test"
'Add a recipient and test to make sure that the
'address is valid using the Resolve method.
With .Recipients.Add("(e-mail address removed)")
.Type = olTo
If Not .Resolve Then
MsgBox "Unable to resolve address.", vbInformation
Exit Sub
End If
End With
'Send the mail message.
.Send
End With
'Release memory.
Set ol = Nothing
Set ns = Nothing
Set newMail = Nothing
End Sub