 publication. Next, the code adds tags to each new page created by the merge. These tags contain the following information:
- The data source used in the merge
- The publication that contains the catalog merge area used in the merge
- Date and time of the merge
The code then creates or increments a document-level tag called "Number Of Merges," which contains the number of merge results that are appended to the specified publication. Finally, the code creates another document-level tag to contain the number of records processed in the current catalog merge.
This example assumes you have created a catalog merge, and written a procedure that calls this function.
Note This example stores information, including the file path and name of the publication and data source used to perform the merge, in the specified publication. Depending on your business processes, storing this information in another publication may present a security concern.
Function ExecuteMergeAndTagPages(filePath As String) Dim d As Document Dim p As Page Dim intPages As Integer Dim i As Integer Dim t As Tag Dim TagExists As Boolean TagExists = False 'Open the publication 'and record current number of pages Set d = Application.Open(filePath) intPages = d.Pages.Count 'Close publication without saving d.Application.Quit 'Append the merge to the specified publication Set d = ActiveDocument.MailMerge.Execute(Pause:=False, _ Destination:=pbMergeToExistingPublication, _ Filename:=filePath) 'Add page-specific tags 'containing merge data information 'to each new page created by the merge For i = (intPages + 1) To d.Pages.Count Set p = d.Pages(i) With p.Tags .Add "Data Source", ActiveDocument.MailMerge.DataSource.Name .Add "Merge Pub", ActiveDocument.FullName .Add "Page Creation Date", CStr(Now) End With Next i 'Find the Number of Merges tag 'if it already exists 'and increment it for this merge For Each t In d.Tags If t.Name = "Number of Merges" Then t.Value = t.Value + 1 TagExists = True Exit For End If Next t 'Create the Number of Merges tag 'if it does not alreay exist If TagExists = False Then d.Tags.Add Name:="Number of Merges", Value:=1 End If 'Create a tag that contains the number of records 'in this specific merge d.Tags.Add Name:="Merge " & d.Tags("Number of Merges").Value & _ " Record No", _ Value:=ActiveDocument.MailMerge.DataSource.RecordCount End Function
Once you store this information, of course, you can write code that programmatically queries the tags and takes action based on the results. You could write a procedure that deletes all the pages created using a certain data source, or created on a specified date.
Scenario: Using Publisher Tags to Store Data Record Information in Shapes
In this next scenario, we merge to a new publication, but we want to persist even more detailed information about the data source. For each shape, we want to know the record in the data source for which it contains information. We also want to know the data source fields for which it contains information, and the value of those data fields. That way, we can manipulate the shapes later based on the data source record for which they were generated, without having to refer back to or alter the data source itself, or regenerate the catalog publication.
Note Again, these examples store detailed information about the data source in the generated catalog publication. Depending on your business processes, this could present a security concern.
First, we need to add tags to the shapes in the catalog merge area that contain merge fields. When Publisher executes a catalog merge, for each record in the data source it copies each shape in the catalog merge area onto the new publication page, replacing the data fields in each shape with the actual record field data.
Figure 1. Example of a catalog merge
1. Data source with record information, such as item names and descriptions
2. Catalog merge template with catalog merge area containing merge fields that are placeholders for record information
3. Resulting merged pages displaying multiple records per page
Publisher copies the shapes 