View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
Web_Builder[_2_] Web_Builder[_2_] is offline
external usenet poster
 
Posts: 10
Default Help sending mail...

Thank you guys very much for your help! Maybe someday I will have learned
enough about VBA to actually answer someone elses question!
Thanks again.


"Dick Kusleika" wrote:


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.

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


The Save method puts it in the Drafts folder, so get rid of that line. The
Send method will put it in the Outbox. When Outlook is running and visible,
ActiveExplorer will return a non-zero ObjPtr, but if it's invisible, there
will be no ActiveExplorer and ObjPtr will return zero. If ObjPtr returns
zero, it will not send and will just save the email to the Drafts folder. I
think you can just get rid of the whole IF block and just Send. If the user
is connected to the internet, it will Send it immediately. If not, it will
store it in the Outbox until a valid Send/Receive is executed from Outlook.

--
Dick Kusleika
MVP - Excel
Excel Blog - Daily Dose of Excel
www.dicks-blog.com