Outlook Class

July 5, 2010

This is a simple class wrapper for creating/displaying Outlook email items with attachments:

Option Explicit

' MailItem CreateItem Type
Const olMailItem = 0        ' = Email

' Attachment Types
Const olByValue = 1         ' = By Value
Const olByReference = 4     ' = By Reference
Const olEmbeddedItem = 5    ' = Embedded Item

Class OutlookEmail
    Private objOE
    Private objMailItem
    Private objAttachments

    Private Sub Class_Initialize
        Set objOE = CreateObject("Outlook.Application")
        Set objMailItem = objOE.CreateItem(olMailItem)
        Set objAttachments = objMailItem.Attachments
    End Sub

    Private Sub Class_Terminate
        Set objAttachments = nothing
        Set objMailItem = nothing
        Set objOE = nothing
    End Sub

    Public Sub AddAttachment(FilePath, DisplayName)
        objAttachments.Add FilePath, olByValue, 1, DisplayName
    End Sub

    Public Sub Display()
    End Sub
End Class

If you just have one attachment for the email, you could use Application.BasicFunctions.QueMessage instead: It will pop up your default email client, populated with whatever parameters you’ve passed.