CHRIS RAE'S VBA PAGES

Routine Archive


Routine:SendMail
Description: Send a mail item using Outlook. Will work from all incarnations of VBA.

Sub SendMail()
    ' Chris Rae's VBA Code Archive - http://chrisrae.com/vba
    ' Code written 19/5/00 by Chris Rae.
    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 "Gates, Bill"
    ' Set recipient (external mail)
    myMailItem.Recipients.Add "bob@microsoft.com"
    ' Set subject
    myMailItem.Subject = "test"
    ' Set body
    myMailItem.body = "Quick test!"
    ' And send it!
    myMailItem.send
    ' Close instance
    Set myOutlook = Nothing
End Sub

You're free to use these routines for anything you want - all I ask is that for commercial use you give me credit somewhere. You may instead want to head back to the index for my Visual Basic for Applications Pages or the main routines archive page.