Attachments.Add Method (Publisher)
Adds an Attachment object to the Attachments collection of a Microsoft Publisher publication.
Version Information
Version Added: Publisher 2007
Syntax
expression .Add(Filename)
expression A variable that represents an Attachments colleciton.
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 e-mail merge. The code adds an attachment to an e-mail 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 e-mail attachment.
Before you can create an e-mail 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 e-mail merge, see the EmailMergeEnvelope object topic.
Public Sub Add_Example()
Dim pubAttachment As Publisher.Attachment
Set pubAttachment = ThisDocument.MailMerge.EmailMergeEnvelope.Attachemts.Add("C:\image.jpg")
Debug.Print ThisDocument.MailMerge.EmailMergeEnvelope.Attachemts.Count
End Sub