LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 213
Default Need Help with SendMail

Hello,

I copied the codes below from Ron de Bruin's web site and used it for my
Excel to email using Outlook. Everything is fine until when I get the
message from Outlook about a program is trying to send something and whether
I want to send it.

If I click "Yes", the email and attachement are sent. However, when I click
"No", I got this error message "Run-time error '287': Application-defined or
object-defined error". I have an option of "End" or "Debug". When I click
on "Debug", it points me to the code ".Send" in the below coding.

My first question is can I write a code to receive the pop-up window from
Outlook and it would send it automatically? If I can't, (my second question
is) what code I should write to avoid the above error message when a user
clicks on "No" on the Outlook window.

Thanks. Here are the codes:

Sub Mail_ActiveSheet_Outlook()
'You must add a reference to the Microsoft outlook Library
Dim OutApp As Outlook.Application
Dim OutMail As Outlook.MailItem
Dim wb As Workbook
Dim strdate As String
strdate = Format(Now, "dd-mm-yy h-mm-ss")
Application.ScreenUpdating = False
ActiveSheet.Copy
Set wb = ActiveWorkbook
With wb
.SaveAs "Part of " & ThisWorkbook.Name _
& " " & strdate & ".xls"
Set OutApp = CreateObject("Outlook.Application")
Set OutMail = OutApp.CreateItem(olMailItem)
With OutMail
.To = "
.CC = ""
.BCC = ""
.Subject = "This is the Subject line"
.Body = "Hi there"
.Attachments.Add wb.FullName
'You can add other files also like this
'.Attachments.Add ("C:\test.txt")
.Send 'or use .Display
End With
.ChangeFileAccess xlReadOnly
Kill .FullName
.Close False
End With
Application.ScreenUpdating = True
Set OutMail = Nothing
Set OutApp = Nothing
End Sub


 
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
sendmail Eef New Users to Excel 4 March 23rd 09 05:55 PM
Sendmail Mattlynn via OfficeKB.com Excel Discussion (Misc queries) 4 August 8th 08 12:21 PM
Sendmail Malcolm Excel Programming 1 November 5th 04 05:37 PM
Sendmail rbaxter[_7_] Excel Programming 1 September 15th 04 04:24 PM
SendMail and BCC Darrin Henry Excel Programming 1 September 13th 03 03:18 PM


All times are GMT +1. The time now is 04:18 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"