MailItem.AttachmentAdd 事件 (Outlook)

向父对象的实例中添加附件时发生。

语法

expressionAttachmentAdd( _Attachment_ )

expression:一个表示 MailItem 对象的变量。

参数

名称 必需/可选 数据类型 说明
Attachment 必需 Attachment 附件 已添加到该项目。

示例

此 Visual Basic for Applications (VBA) 示例在添加附件后检查项目的大小,如果其大小超过 500,000 字节,则将显示一则警告。 示例代码必须放在 类模块(如 ThisOutlookSession)中,并且 TestAttachAdd() 应在 Microsoft Outlook 调用事件过程之前调用过程。

Public WithEvents newItem As Outlook.MailItem 
 
 
 
Private Sub newItem_AttachmentAdd(ByVal newAttachment As Attachment) 
 
 If newAttachment.Type = olByValue Then 
 
 newItem.Save 
 
 If newItem.Size > 500000 Then 
 
 MsgBox "Warning: Item size is now " & newItem.Size & " bytes." 
 
 End If 
 
 End If 
 
End Sub 
 
 
 
Public Sub TestAttachAdd() 
 
 Dim atts As Outlook.Attachments 
 
 Dim newAttachment As Outlook.Attachment 
 
 
 
 Set newItem = Application.CreateItem(olMailItem) 
 
 newItem.Subject = "Test attachment" 
 
 Set atts = newItem.Attachments 
 
 Set newAttachment = atts.Add("C:\Test.txt", olByValue) 
 
End Sub

另请参阅

MailItem 对象

支持和反馈

有关于 Office VBA 或本文档的疑问或反馈? 请参阅 Office VBA 支持和反馈,获取有关如何接收支持和提供反馈的指南。