Use the below code, and change the file name(c:\abc.zip) to whatever you want to attach, if anything; and obviously the email addresses (me@...) to whomever you want to send to.
Private Sub Command2_Click()
Dim patha As String
Dim result As Integer
Dim displaymessage As Boolean
Dim objOutlook As Outlook.Application
Dim objOutlookMsg As Outlook.MailItem
Dim objOutlookRecip As Outlook.Recipient
Dim objOutlookAttach As Outlook.Attachment
patha = [color red]"c:\abc.zip"[/color]
displaymessage = True
' Create the Outlook session.
Set objOutlook = CreateObject("Outlook.Application")
' Create the message.
Set objOutlookMsg = objOutlook.CreateItem(olMailItem)
With objOutlookMsg
' Add the To recipient(s) to the message.
Set objOutlookRecip = .Recipients.Add([color red]"me@..."[/color])
objOutlookRecip.Type = olTo
' Add the CC recipient(s) to the message.
Set objOutlookRecip = .Recipients.Add([color red]"me@..."[/color])
objOutlookRecip.Type = olCC
' Add the BCC recipient(s) to the message.
Set objOutlookRecip = .Recipients.Add([color red]"me@..."[/color])
objOutlookRecip.Type = olBCC
' Set the Subject, Body, and Importance of the message.
.Subject = "This is an Automation test with Microsoft Outlook"
.Body = "This is the body of the message." & vbCrLf & vbCrLf
.Importance = olImportanceHigh 'High importance
' Add attachments to the message.
'If Not IsMissing(AttachmentPath) Then
Set objOutlookAttach = .Attachments.Add(patha)
'End If
' Resolve each Recipient's name.
For Each objOutlookRecip In .Recipients
objOutlookRecip.Resolve
Next
' Should we display the message before sending?
If displaymessage Then
.Display
Else
.Save
.Send
End If
End With
Set objOutlook = Nothing
End Sub
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.