Dim OutlookApp As Outlook.Application
Dim objOutlookMsg As Outlook.MailItem
Dim objOutlookRecip As Outlook.Recipient
Dim objOutlookAttach As Outlook.Attachment
Dim strTitle As String
Dim strMessage As String
'create the Outlook session
Set OutlookApp = GetObject(, "Outlook.Application")
If Err.Number <> 0 Then
Set OutlookApp = CreateObject("Outlook.Application")
End If
On Error GoTo ErrPoint
'create the message.
Set objOutlookMsg = OutlookApp.CreateItem(olMailItem)
'On Error Resume Next
With objOutlookMsg
'add the Recipient(s), Subject, Body, and attachments to the message.
Set objOutlookRecip = .Recipients.Add(pstrTo)
objOutlookRecip.Type = olTo
.CC = pstrCC
.Subject = pstrSub
.Body = pstrMsg & vbCrLf & vbCrLf & pstrSig & vbCrLf & vbCrLf
If Not IsMissing(pvarAttachmentPath) Then
Set objOutlookAttach = .Attachments.Add(pvarAttachmentPath)
End If
'resolve each Recipient's name.
For Each objOutlookRecip In .Recipients
objOutlookRecip.Resolve
If Not objOutlookRecip.Resolve Then
objOutlookMsg.Display
End If
Next
.Display
End With
'On Error GoTo ErrPoint
|