Add Method (Attachments Collection)

Applies To

Attachments collection object.

Description

Creates a new attachment in the Attachments collection, and returns the new attachment as an Attachment object.

Syntax

expression.Add(Source, Type, Position, DisplayName)

expression An expression that returns an Attachments object.

Source Required String. The file (represented by the full path and file name) or item that constitutes the attachment.

Type Optional Long. The type of attachment. Can be one of the following OlAttachmentType constants: olByReference, olByValue, olEmbeddedItem, or olOLE.

Position Optional Long. The position of the attachment within the body text of the message.

DisplayName Optional String. The display name of the attachment.

Example

This example creates a new mail message, attaches a Microsoft Excel workbook as an attachment (not a link) and gives the attachment a descriptive caption.

Set myItem = myOlApp.CreateItem(olMailItem)
Set myAttachments = myItem.Attachments
myAttachments.Add "C:\My Documents\Q496.xls", _
    olByValue, 1, "4th Quarter 1996 Results Chart"
This example creates a new mail message and attaches a Microsoft Word document from a server using a link.

Set myItem = myOlApp.CreateItem(olMailItem)
Set myAttachments = myItem.Attachments
myAttachments.Add "\\MYSVR1\Reports\Q496Report.doc", _
    olByReference
This example creates a new mail message and attaches the first contact in the default Contacts folder.

Set myFolder = _
    olNameSpace.GetDefaultFolder(olFolderContacts)
Set myFirstContact = myFolder.Items(1)
Set myItem = myOlApp.CreateItem(olMailItem)
Set myAttachments = myItem.Attachments
myAttachments.Add myFirstContact