Routine Archive

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

Sub SendMail()
    ' Chris Rae's VBA Code Archive -
    ' 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 ""
    ' Set subject
    myMailItem.Subject = "test"
    ' Set body
    myMailItem.body = "Quick test!"
    ' And send it!
    ' 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.