Attachments.Add method (Outlook)
Creates a new attachment in the Attachments collection.
expression.Add (Source, Type, Position, DisplayName)
expression A variable that represents an Attachments object.
|Source||Required||Variant||The source of the attachment. This can be a file (represented by the full file system path with a file name) or an Outlook item that constitutes the attachment.|
|Type||Optional||Long||The type of the attachment. Can be one of the OlAttachmentType constants.|
|Position||Optional||Long||This parameter applies only to email messages using the Rich Text format: it is the position where the attachment should be placed within the body text of the message. A value of 1 for the Position parameter specifies that the attachment should be positioned at the beginning of the message body. A value 'n' greater than the number of characters in the body of the email item specifies that the attachment should be placed at the end. A value of 0 makes the attachment hidden.|
|DisplayName||Optional||String||This parameter applies only if the mail item is in Rich Text format and Type is set to olByValue : the name is displayed in an Inspector object for the attachment or when viewing the properties of the attachment. If the mail item is in Plain Text or HTML format, then the attachment is displayed using the file name in the Source parameter.|
An Attachment object that represents the new attachment.
When an Attachment is added to the Attachments collection of an item, the Type property of the Attachment will always return olOLE (6) until the item is saved. To ensure consistent results, always save an item before adding or removing objects in the Attachments collection.
The following Microsoft Visual Basic /Visual Basic for Applications (VBA) example creates a mail item, adds an attachment by embedding it at the beginning of the message body, and displays it. To run this example, make sure the attachment which is a file called Test.Doc exists in the C:\ folder.
Sub AddAttachment() Dim myItem As Outlook.MailItem Dim myAttachments As Outlook.Attachments Set myItem = Application.CreateItem(olMailItem) Set myAttachments = myItem.Attachments myAttachments.Add "C:\Test.doc", _ olByValue, 1, "Test" myItem.Display End Sub
Attach a File to a Mail Item Attach an Outlook Contact Item to an Email Message Limit the Size of an Attachment to an Outlook Email Message Modify an Attachment of an Outlook Email Message
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.