Sdílet prostřednictvím


BeforeAttachmentSave Event

Occurs just before an attachment is saved.

Subobject**_BeforeAttachmentSave(ByVal Attachment As Attachment, Cancel As Boolean)**

*object   * An expression that evaluates to one of the objects in the Applies To list. In Microsoft Visual Basic Scripting Edition (VBScript), use the word Item.

*Attachment    * Required. The Attachment to be saved.

Cancel Optional (not used in VBScript). False when the event occurs. If the event procedure sets this argument to True, the save operation is not completed and the attachment is not changed.

Remarks

This event corresponds to when attachments are saved to the messaging store. The BeforeAttachmentSave event occurs just before an attachment is saved when an item is saved. If a user edits an attachment and then saves those changes, the BeforeAttachmentSave event will not occur at that time; instead it will occur when the item itself is later saved. It also does not occur when the attachment is saved on the hard disk using the SaveAsFile method.

In VBScript, if you set the return value of this function to False, the save operation is cancelled and the attachment is not changed.

Example

This Visual Basic for Applications (VBA) example notifies the user that the user is not allowed to save the attachment. The Cancel argument is set to True to cancel the save operation. The sample code must be placed in a class module such as ThisOutlookSession, and the TestAttachSave() procedure should be called before the event procedure can be called by Microsoft Outlook.

Public WithEvents myItem As Outlook.MailItem
Public olApp As New Outlook.Application


Private Sub myItem_BeforeAttachmentSave(ByVal myAttachment As Attachment, Cancel As Boolean)
    MsgBox "You are not allowed to save " & myAttachment.FileName
    Cancel = True
End Sub

Public Sub TestAttachSave()
    Set olApp = CreateObject("Outlook.Application")
    Set myItem = olApp.ActiveInspector.CurrentItem
End Sub

Applies to | AppointmentItem Object | ContactItem Object | DistListItem Object | DocumentItem Object | JournalItem Object | MailItem Object | MeetingItem Object | PostItem Object | RemoteItem Object | ReportItem Object | TaskItem Object | TaskRequestAcceptItem Object | TaskRequestDeclineItem Object | TaskRequestItem Object | TaskRequestUpdateItem Object

See Also | Attachment Object | AttachmentAdd Event | AttachmentRead Event | Using events with Automation