相关文章推荐
求醉的剪刀  ·  element-ui ...·  1 年前    · 
烦恼的四季豆  ·  create react app - ...·  1 年前    · 

This browser is no longer supported.

Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.

Download Microsoft Edge More info about Internet Explorer and Microsoft Edge

Occurs when an attachment has been added to an instance of the parent object.

Syntax

expression . AttachmentAdd ( _Attachment_ )

expression A variable that represents a MailItem object.

Parameters

Required/Optional Data type Description

Example

This Visual Basic for Applications (VBA) example checks the size of the item after an attachment has been added and displays a warning if the size exceeds 500,000 bytes. The sample code must be placed in a class module such as ThisOutlookSession , and the TestAttachAdd() procedure should be called before the event procedure can be called by 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

See also

MailItem Object

Support and feedback

Have questions or feedback about Office VBA or this documentation? Please see Office VBA support and feedback for guidance about the ways you can receive support and provide feedback.