og publication if we want to make a change. For example, suppose we later decide to offer a ten percent discount on any item priced over $10. We could add an additional column for the discount price to the data source, and then regenerate the catalog. However, we may not have permission to alter the data source, and we may have further customized the catalog with changes that are lost if we regenerate it. Because of the information we store in the tags, we can accomplish the same thing without either altering the source files or losing our custom changes.
The following code finds all the text boxes that contain a Price tag. If the Price Tag object Value property is greater than 10, the code calculates a discounted price and inserts text listing that price into the shape.
Function DisplayDiscount(d As Document) Dim sr As ShapeRange Dim sh As Shape Dim dis As Single Dim txt As TextRange With d 'Find all shapes with a Price tag Set sr = .FindShapesByTag("Price") If Not sr Is Nothing Then For Each sh In sr 'If the Price is greater than ten dollars If sh.Tags("Price").Value > 10 Then 'Create a discount price dis = (sh.Tags("Price").Value) - ((sh.Tags("Price").Value) * 0.1) 'Add text to the shape 'that lists the discount price Set txt = sh.TextFrame.TextRange.InsertAfter _ (NewText:=vbLf & "Now only " & CStr(Round(dis, 2)) & "! Save 10%") 'Format discount price text With txt .Font.Color.RGB = 255 .Font.Bold = msoTrue End With End If Next sh End If End With End Function
Below is a diagram of the Publisher object model section pertaining to the Tags collection.
Figure 3. The Tags object model section of Publisher
Hopefully, you can see just how flexible and useful tags can be to track programmatic metadata. Whether it's attribute information that isn't already tracked in any available object model properties, or variable data that is needed for running some procedure or programmatic functionality, tags are an ideal storage mechanism for persisting the data you need for your business processes within your publications themselves.
This section lists resources you can use to learn more about the products and technologies mentioned or used in this article.