Attachments.Add method (Publisher)

Adds an Attachment object to the Attachments collection of a Microsoft Publisher publication.

Syntax

expression.Add (FileName)

expression A variable that represents an Attachments object.

Parameters

Name Required/Optional Data type Description
FileName Required String File name of the attachment.

Return value

Attachment

Example

The following Microsoft Visual Basic for Applications (VBA) macro shows how to add an attachment to the message in an email merge. The code adds an attachment to an email message and then prints the number of current attachments to the message in the Immediate window.

The attachment in this example is an image file at the root of the C drive. Before running the code, replace "C:\image.jpg" with the path to and name of the file on your computer that you want to add as an email attachment.

Before you can create an email merge, you must use the OpenDataSource method of the MailMerge object to connect the active document to a data source. To run the merge, use the Execute method of the MailMerge object.

For an example of how to connect to a data source and create an email merge, see the EmailMergeEnvelope object.

Public Sub Add_Example() 
 
 Dim pubAttachment As Publisher.Attachment 
 
 Set pubAttachment = ThisDocument.MailMerge.EmailMergeEnvelope.Attachments.Add("C:\image.jpg") 
 Debug.Print ThisDocument.MailMerge.EmailMergeEnvelope.Attachments.Count 
 
End Sub

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.