Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Sendmail - Allow Message Edits

Status
Not open for further replies.

NMiller007

Programmer
Nov 15, 2006
65
US
I was using .SendMail to send an Excel document that was just formatted (all of this is done from an Access macro). When I didn't define recipients, the message box would pop-up and the user could edit the body and then send.

Now they want the recipients defined, so I added that in, but now the message tries to send automatically, giving me a warning.

Can I use .SendMail to open a new message (with the recipients and subject defined) and allow the user to paste in some body text before sending (I'm assuming this would also get rid of the send warning)?
 
I managed to find some other code that used an Outlook object to do this.

Code:
Dim myApp As New Outlook.Application
Dim myItem As MailItem
    
Set myItem = myApp.CreateItem(olMailItem)
                
With myItem
   .To = strTo
   .Subject = MailSubject
   .Attachments.Add objWB.FullName
   .Display
End With

I also had to make sure I added the Outlook library.

Before, I was using this:
Code:
Set objWB = .Workbooks.Open("ThisFile.xls")
objWB.SendMail strTo, MailSubject
Would objWB.Display have worked?

Thanks!
 
If you want to bypass the annoying Outlook security popup warning, download Redemption for Outlook.

Code:
' Tool -> References -> Redemption Outlook Library
' Tool -> References -> Microsoft Outlook xx.0 Object Library

Sub Send_Mail()
   Call Send_Email("b@b.com", "Subject", "Body")
   Call Send_Email("b@b.com", "Subject", "Body", "C:\Documents and Settings\WinblowsME\Desktop\Temp.xls")
End Sub

Private Sub Send_Email(mail_to As String, subject As String, body As String, Optional attachment As String = "")
   Dim ol As Outlook.Application
   Dim mail_item As Object

   Set ol = New Outlook.Application
   Set mail_item = New Redemption.SafeContactItem
   
   With mail_item
      .Item = ol.CreateItem(olMailItem)
      .To = mail_to
      .subject = subject
      .body = body
   End With
   
   If attachment <> "" Then
      mail_item.Attachments.Add (attachment)
   End If

   mail_item.Send
   
   Set mail_item = Nothing
   Set ol = Nothing
End Sub
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top