Automating Outlook:   Return to List

' A referece to the installed Outlook library must be made under TOOLS | REFERENCES (in VBA) or PROJECT | REFERENCES in (VB)

Sub SendMail()' This routine will work will all incarnations of VBA
Dim myOutlook As Object
    Dim myMailItem As Object
    ' Make instance
    Set myOutlook = CreateObject("Outlook.Application")
    ' Make mail item
    Set myMailItem = myOutlook.createitem(0)
    ' Set recipient (internal mail)
    myMailItem.Recipients.Add "Doe, John"
    ' Set recipient (external mail)
    myMailItem.Recipients.Add "JDoe@Yahoo.com"
    ' Set subject
    myMailItem.Subject = "test"
    ' Set body
    myMailItem.body = "Quick test!"
    ' And send it!
    myMailItem.send
    ' Close instance
    Set myOutlook = Nothing
End Sub

See also:
Automating Database Compaction (every 5 times)
Automating Multiple Applications
Automating Access (Reports)
Automating Internet Explorer from Excel
Outlook Automation from within Excel
Powerpoint Automation (complex!) from within Excel
Word Automation from Excel
Code (via Automation) to Import Tab-Delimited File into Excel
Determining File Association (uses API)
Excel chart creation through Automation
Outlook Automation
Automation of Word (getting or starting Word)



Note to Webmaster