Close Method

Microsoft Outlook Visual Basic

Show All

Close Method

       

For the Explorer object, the Close method closes the explorer. No information is saved.

For an Inspector or Microsoft Outlook item object, the Close method closes the inspector or item and optionally saves changes to the displayed Outlook item.

expression.Close(SaveMode)

expression   Required. An expression that returns one of the objects in the Applies To list.

SaveMode   This argument is used with all objects in the Applies To list except for the Explorer object. Required OlInspectorClose. The close behavior. If the item displayed within the inspector has not been changed, this argument has no effect.

OlInspectorClose can be one of these OlInspectorClose constants.
olDiscard Discard all changes without prompting.
olPromptForSave Prompt to save or discard all changes.
olSave Save all changes without prompting.

Example

This Visual Basic for Applications example uses CreateItem to open a mail message, adds a recipient to it to introduce a change, then uses the Close method to close the item and prompt the user to save changes.

Set myOlApp = CreateObject("Outlook.Application")
Set myItem = myOlApp.CreateItem(olMailItem)
myItem.Recipients.Add "David Goodhand"
myItem.Close olPromptForSave

If you use VBScript, you do not create the Application object, and you cannot use named constants. This example shows how to perform the same task using VBScript.

Set myItem = Application.CreateItem(0)
myItem.Recipients.Add "David Goodhand"
myItem.Close 2