會在附件已新增至父物件的執行個體時發生。
語法
expression。
AttachmentAdd( _Attachment_ )
運算式 代表 TaskItem 物件的變數。
參數
| 名稱 | 必要/選用 | 資料類型 | 描述 |
|---|---|---|---|
| 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
另請參閱
支援和意見反應
有關於 Office VBA 或這份文件的問題或意見反應嗎? 如需取得支援服務並提供意見反應的相關指導,請參閱 Office VBA 支援與意見反應。