Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,272
Default Help sending mail...

Dim olApp As Object

On Error Resume Next
Set olApp = GetObject(, "Outlook.Application")
On Error GoTo 0
If Not olApp Is Nothing Then
MsgBox "Outlook is already open"


--

HTH

Bob Phillips
... looking out across Poole Harbour to the Purbecks
(remove nothere from the email address if mailing direct)

"Web_Builder" wrote in message
...
Hi, I have found so much usefully information in this group hopefully

someone
can help with this one. I got this code initially from Don Lloyd and

changed
it to fit what I need. The problem is if Outlook is open I don't get the
little warning from Outlook and instead of sending the email it places it

in
the drafts folder. If Outlook is closed everything works fine. Could
someone please tell me if there is an error in my code or if not how at

the
begining of my code I can make sure that Outlook is actually closed?

Thanks
alot!

Sub Emailpage_Button5_Click()

If Dir("c:\test") < "" Then
MkDir "c:\test"
Else

End If

MsgBox "If you are not already connected to the internet, please connect

now
and press OK when you are ready to continue. If you choose not to connect
press OK and your email will be placed in Outlook's Out Box and you will

have
to manually press Send to send it."

MsgBox "When Outlook asks if you would like to allow another program to

send
mail please press yes."

Dim Fname, Sbjct, Bdy, Recpt

Fname = "C:\MailTemp\" & "TempMail.xls" ' - I used this for testing
Sbjct = "This is a test." ' - can be cell contents. eg Sbjct =

Range("A1")
Bdy = "Test e-mail order. Open attachment to see the order form." ' -

As
above
Recpt = "

ActiveSheet.Copy ' The copied sheet becomes the active workbook
If Dir(Fname) < "" Then Kill Fname ' If Fname already exists, this will
delete it
ActiveWorkbook.SaveAs Fname 'Saves the Sheet - now a workbook - to be

sent
ActiveWorkbook.Close False ' The workbook has to be closed to be attached

With CreateObject("Outlook.Application")
With .CreateItem(0) 'olMailItem
.To = Recpt ' The recipient's email address
.Subject = Sbjct
.Body = Bdy
.Attachments.Add Fname
.Save
If ObjPtr(.Parent.Session.Application.ActiveExplorer) = 0 Then
.Send
End If
End With
End With

Kill Fname ' Deletes the disc copy of the attachment - optional

MsgBox "Your e-mail order has been sent" ' Well done!!



End Sub



Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Error when sending mail with CDO Amedee Van Gasse Excel Discussion (Misc queries) 5 November 28th 08 01:51 PM
Sending a blank e-mail Hawksby Excel Discussion (Misc queries) 1 September 25th 07 09:16 AM
General mail failure when sending e-mail from Excel Adrienne Excel Discussion (Misc queries) 5 November 4th 05 12:59 PM
Sending E-mail litew_8 Excel Worksheet Functions 1 November 21st 04 06:13 AM
Sending Mail from within Excel Don Lloyd Excel Programming 2 July 24th 04 09:28 PM


All times are GMT +1. The time now is 03:35 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"