Public Function CreateEmailWithOutlook( _
MessageTo As String, _
MessageCC As String, _
Subject As String, _
MessageBody As String, _
AttachmentFile As Variant)
' Define app variable and get Outlook using the "New" keyword
Dim olApp As New Outlook.Application
Dim olMailItm As Outlook.MailItem ' An Outlook Mail item
Dim olFolder As Outlook.Folder
Dim olNameSpace As Outlook.NameSpace
Dim varItem As Variant
Set olApp = New Outlook.Application
Set olNameSpace = olApp.GetNamespace("MAPI")
Set olFolder = olNameSpace.GetDefaultFolder(olFolderInbox)
' Create a new email object
Set olMailItm = olFolder.Items.Add(olMailItem)
' Add the To/Subject/Body to the message and display the message
With olMailItm
.To = MessageTo
.CC = MessageCC
.Subject = Subject
.Body = MessageBody
' request a readers reciept so I know the email has been read
.ReadReceiptRequested = True
If IsArray(AttachmentFile) Then
For Each varItem In AttachmentFile
.Attachments.Add varItem
Next
Else
.Attachments.Add AttachmentFile
End If
.Display ' To show the email message to the user
'.Send
End With
' Release all object variables
Set olMailItm = Nothing
Set olFolder = Nothing
Set olNameSpace = Nothing
Set olApp = Nothing
End