|Publisher Developer Reference|
Version Added: Publisher 2007
The properties of the EmailMergeEnvelope object correspond to the combination of both required and optional settings in the Merge to E-mail dialog box in the Publisher user interface (on the File menu, point to Send E-mail, click Send E-mail Merge, and then click Options).
Before you can use the Execute method of the MailMerge object to send a merged e-mail, you must specify a value for the To property of the EmailMergeEnvelope object, or Publisher will return an error.
The following Microsoft Visual Basic for Applications (VBA) macro shows how to assign some of the properties of an EmailMergeEnvelope object that represents an e-mail merge and then send the resulting e-mail message, an invitation. The macro connects to a data source, assigns values to the To and Subject properties of the EmailMergeEnvelope object, and adds a text box containing merge fields and some additional text to the e-mail message. Then it uses the Execute method of the MailMerge object to execute the merge and send the e-mail.
The data source referenced in this example is a simple tab-deliimited text file that contains three columns with the headings "First," "Last," and "E-mail Address" respectively.
Before running the code, create the text file, add one or more data rows, name the file DataSource.txt, and save it to disk. Then add the file's path to the code by replacing the PathToFile variable with your path.
If you run the code in this example more than once, you will encounter errors because Publisher connects to the data source each time you run the code, resulting in a publication connected to multiple data sources. When multiple data-source connections exist, Publisher inserts an extra column in the master (combined) mail-merge data source to specify the specific data source for each record. As a result, Publisher effectively changes the index number of all the data-source columns, making the indexes used in this code (for example, MailMergeField1) incorrect.
|Visual Basic for Applications|