Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to send Outlook email from other MS Office Apps.

Outlook FAQs

How to send Outlook email from other MS Office Apps.

by  SQLBI  Posted    (Edited  )
There are a regular number of posts asking how to send emails from various other applications. The following code will create an instance of MS Outlook from any MS Office Application and send an email based on a number of variables.

Code:
Public Sub SendEmail()

Dim olApp As Object
Dim subject As String
Dim olMailItem
Dim newMail
Dim newRecipient
Dim mailBody As String
Dim strAddress As String

subject = "Your text here"
***This can be hard typed or a variable passed from another part of your program.
Code:
mailBody = "Your text here"
***This can be hard typed or a variable passed from another part of your program.
Code:
strAddress = "Email Address Here"
***This can be hard typed or a variable passed from another part of your program.


Code:
Set olApp = CreateObject("Outlook.Application")
Set newMail = olApp.CreateItem(olMailItem)
Set newRecipient = newMail.Recipients.Add(strAddress)

With newMail
.subject = subject
.body = mailBody
End With

newMail.send
    
olApp.Quit
Set olApp = Nothing
Set newMail = Nothing
Set newRecipient = Nothing

End Sub

Hope this helps.
Register to rate this FAQ  : BAD 1 2 3 4 5 6 7 8 9 10 GOOD
Please Note: 1 is Bad, 10 is Good :-)

Part and Inventory Search

Back
Top