+ Reply to Thread
Results 1 to 2 of 2

send mail and close workbook immediatly

Hybrid View

  1. #1
    Registered User
    Join Date
    01-02-2009
    Location
    US
    MS-Off Ver
    Excel 2003
    Posts
    1

    send mail and close workbook immediatly

    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

  2. #2
    Forum Contributor VBA Noob's Avatar
    Join Date
    04-25-2006
    Location
    London, England
    MS-Off Ver
    xl03 & xl 07(Jan 09)
    Posts
    11,988
    Your post does not comply with Rule 3 of our Forum RULES. Use code tags around code. Posting code without them makes your code hard to read and difficult to be copied for testing. Highlight your code and click the # at the top of your post window. For more information about these and other tags, found here

    VBA Noob
    _________________________________________


    Credo Elvem ipsum etian vivere
    _________________________________________
    A message for cross posters

    Please remember to wrap code.

    Forum Rules

    Please add to your signature if you found this link helpful. Excel links !!!

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1