Compartilhar via


AttachmentRead Event

Occurs when an attachment in an e-mail item has been opened for reading.

Subobject**_AttachmentRead(ByVal Attachment As Attachment)**

*object    * An object 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 that was opened.

Example

This Visual Basic for Applications (VBA) example displays a message when the user tries to read an attachment. The sample code must be placed in a class module such as ThisOutlookSession, and the TestAttachRead() procedure should be called before the event procedure can be called by Microsoft Outlook. For this example to run, there has to be at least one item in the Inbox with subject as 'Test' and containing at least one attachment.

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

Private Sub myItem_AttachmentRead(ByVal myAttachment As Outlook.Attachment)
    If myAttachment.Type = olByValue Then
        MsgBox "If you change this file, also save your changes to the original file."
    End If
End Sub

Public Sub TestAttachRead()
    Dim atts As Outlook.Attachments
    Dim myAttachment As Outlook.Attachment

    Set olApp = CreateObject("Outlook.Application")
    Set myItem = olApp.ActiveExplorer.CurrentFolder.Items("Test")
    Set atts = myItem.Attachments
    myItem.Display
End Sub

This VBScript example reminds the user to also save changes to the original file.

Sub Item_AttachmentRead(ByVal ReadAttachment)
    If ReadAttachment.Type = 1 then
        MsgBox "If you change this file, also save your changes to the original file."
    End If
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 | BeforeAttachmentSave Event | Using events with Automation