共用方式為


Outlook) (MailItem.AttachmentAdd 事件

會在附件已新增至父物件的執行個體時發生。

語法

expressionAttachmentAdd( _Attachment_ )

表達 代表 MailItem 物件的 變數。

參數

名稱 必要/選用 資料類型 描述
Attachment 必要 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 支援與意見反應