Hi,

Below is the code I am using to send a mail and close the workbook in Auto_Open function. I have scheduled a batch file to open this excel for every XX minutes. My problem is that MYSendmail function is not sending the keys (to avoid prompts for speel check) and immeditly calliing workbook.close(FALSE). I mean sendmail function displays the new message and close the excel by leaving the new mail mesage with out sending.

If i remove workbook.close(FALSE) everything work fine.

Anyony please help to close the workbook immediatly after sending the email.

Thanks In Advance-

Sub Auto_Open()
Call MYSendMail(MySubject, MyBody, MailTo)
ThisWorkbook.Close (False)
End Sub


Sub MYSendMail(EMSubject As String, EMBody As String, EMTo As String)
Dim Email As String, Subj As String
Dim Msg As String, URL As String
Dim r As Integer, x As Double

Email = EMTo
Subj = EMSubject
Msg = EMBody
Msg = Application.WorksheetFunction.Substitute(Msg, vbCrLf, "%0D%0A")

URL = "mailto:" & Email & "?subject=" & Subj & "&body=" & Msg
ShellExecute 0&, vbNullString, URL, vbNullString, vbNullString, vbNormalFocus

' Wait two seconds before sending keystrokes
Application.Wait (Now + TimeValue("0:00:02"))

'Send Alt + S key to send mail
Application.SendKeys "%s"

'Send Alt + g key to ignore spell check
Application.SendKeys "%g"
End Sub