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
|