Send email from vba code in excel

M

Melisa Hutchins

Help!
I need to write code to send a work book when it is saved or when it i
closed. This is what I have but it will not send the email. I am usin
excel 2003. I am very new to VBA.

Sub Email()
Dim OutApp As Object
Dim OutMail As Object
email_ = Range("F5") & ";" & Range("F3")
cc_ = ""
subject_ = "Flagged Order"
body_ = "New Flagged Order"
Set OutApp = CreateObject("Outlook.Application")
Set OutMail = OutApp.CreateItem(0)
With OutMail
.To = email_
.Subject = subject_
.Body = body_
.CC = cc_
.Display
End With
Set OutMail = Nothing
Set OutApp = Nothing
End With
End With
End Su
 
N

Norm

I had the same question please look at the help I recieved it worked for me
see the threads: For Outlook "auto email worksheet and for Lotus Notes see:
"Outlook vs Lotus Notes in macros"
 
R

robert_guild

This will work but Outlook will give you a pop up requiring permissio
to send the email.

Private Sub SendEmail()

On Error GoTo Proc_Err

Dim outApp As Object
Dim objSession As Object

Dim objMessage As Object
Dim objRecipient As Object
Dim objAttachments As Object

'Utility variables
Dim i As Integer
Dim sSubject As String
Dim sText As String
Dim sName As String
Dim sAttachment As String

sText = "This is a test of email interface."
sSubject = "Test message"
sName = "(e-mail address removed)"

'Get path to attachment.
sAttachment = "C:\Documents and Settings\Robert\M
Documents\Demos\App-Splash-Page.jpg"

Set outApp = CreateObject("Outlook.Application")
Set objSession = outApp.Session

'Create the message object
Set objMessage = outApp.CreateItem(0)

'Feed the required property values for the message
objMessage.Subject = sSubject
objMessage.body = sText
Set objAttachments = objMessage.attachments
objAttachments.Add sAttachment, 1, 1, "App Splash Page"
'Create a recipient for this message
Set objRecipient = objMessage.Recipients.Add(sName)
'Set the recipient properties
objRecipient.Type = 1
objRecipient.resolve

'Send the message
objMessage.send

'Clean up objects
Set objRecipient = Nothing

Set objMessage = Nothing
Set outApp = Nothing

Proc_Exit:
Exit Sub

Proc_Err:
sText = "Error Line: " & Erl & " Error: " & Err.Number & " " & vbCr
Err.Description
MsgBox sText, vbCritical
GoTo Proc_Exit

End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top