vbaoutlookoutlook-form

Custom Outlook From could not be closed with ".Close"


I have a created a custom outlook form using VBA. I want send a mail and then close the form just by by clicking a button. The mail should be sent and following that the form should get closed. The have written the following code, but this close the form after prompting the user to save changes. The user hast to close the prompted kinda MsgBox and then the form.

Sub cmdbut2_Click
    Set myItem = Application.CreateItem(0)
    myItem.Recipients.Add "Test Test"
    myItem.Close 2
End Sub

I want to close the form without and prompted messages. How can I do this?


Solution

  • You should pass olSave value to MailItem.Close method.

    Sub cmdbut2_Click
        Set myItem = Application.CreateItem(0)
        myItem.Recipients.Add "Test Test"
        'myItem.Close 2 close with prompt for save
        myItem.Close olSave
    End Sub