Saturday, February 6, 2016

Excel/Access VBA that sends email via Outlook




Here's the code that send email via Outlook using MS Access VBA.  You need to add a reference to the Outlook object model in the Visual Basic editor. Then you can use the code below to send an email using outlook.   




Sub sendEmailUsingOutlook()
Dim xMail As MailItem
Dim xApp As Outlook.Application
Set xApp = CreateObject("Outlook.application")
Set xMail = oApp.CreateItem(olMailItem)

xMail.Subject = "Your Subject Here"

xMail.Body = "The body of the email here"
xMail.Cc = "Cc Email here"
xMail.To = "emailadd@add.com"
xMail.Send

Set oMail = Nothing

Set oApp = Nothing
End Sub



No comments:

Post a Comment