Outlook Class

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.


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: