Databases Reference
In-Depth Information
FIGURE 6.11 Referencing the Outlook Object Library.
This functionality can be tested by selecting A DA->Chapter 6 -> O utlook Mail. (The address
will need to be changed in VBA code from “name@domain.com” to the desired destination, as
well as the path to the file that is to be attached and mailed.)
Sub Send_Msg_Using_Outlook()
Dim objOL As New Outlook.Application
Dim objMail As MailItem
Dim CRLF As String
CRLF = Chr(13) + Chr(10)
Set objOL = New Outlook.Application
Set objMail = objOL.CreateItem(olMailItem)
With objMail
.To = "name@domain.com"
.Subject = "Automated Mail Response"
.Body = "This is an automated message generated in Excel
VBA." & CRLF & _
"A Worksheet Cell Item Can be send by utilizing the commented
code below: " '& _
'Format(range("A1").Value, "$ #,###.#0") & "."
.Attachments.Add "C:\temp\junk.xls", , 0
'0 = Hidden Attachment
'1 = Beginning of Email
.Display
End With
'To Actually Send Message Uncomment Next Statement
objMail.Send
Set objMail = Nothing
Set objOL = Nothing
End Sub
Search WWH ::




Custom Search