From: Melisa Hutchins on

Help!
I need to write code to send a work book when it is saved or when it is
closed. This is what I have but it will not send the email. I am using
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 Sub




--
Melisa Hutchins
From: Norm on
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"

"Melisa Hutchins" wrote:

>
> Help!
> I need to write code to send a work book when it is saved or when it is
> closed. This is what I have but it will not send the email. I am using
> 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 Sub
>
>
>
>
> --
> Melisa Hutchins
> .
>
From: robert_guild on

This will work but Outlook will give you a pop up requiring permission
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 = "rguild(a)reportsuwant.com"

'Get path to attachment.
sAttachment = "C:\Documents and Settings\Robert\My
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


--
robert_guild
------------------------------------------------------------------------
robert_guild's Profile: http://www.thecodecage.com/forumz/member.php?u=1512
View this thread: http://www.thecodecage.com/forumz/showthread.php?t=199846

http://www.thecodecage.com/forumz