Using Tags to Store Custom Information in Publisher 2003 and Publisher 2002
Microsoft Office Publisher 2003
Microsoft Publisher 2002
Summary: You can use the Tags collection to persist a wide range of custom information within your publication, at the publication, page, or shape level. View an in-depth example of using tags to store data source information in a catalog merge publication. (16 printed pages)
What Are Publisher Tags?
Adding, Editing, and Deleting Custom Tags
Catalog Merge Scenarios Using Publication, Page, and Shape Tags
Publisher Tags Object Model Hierarchy
Using the various members of the Publisher object model, you can set and persist many different kinds of information in a publication. But sometimes there's custom information you want to save with the publication that isn't represented by any method or property in the Publisher object model. For those cases, the Tags collection enables you to persist custom information in a publication at the publication, page, or shape level.
In this article we'll explain what tags are and how to use them. We'll show you a few simple examples of tags in use, and then walk you through a more complex example that uses tags to store merge information at the publication, page, and shape level.
Tags are, in essence, generic storage bins where you can place whatever custom information, or metadata, you want to persist with the publication. The Tags collection is a child of the Document, Page, ShapeRange, and Shape objects, so you can save data at the publication, page, or individual shape level.
Each Tag object contains two main properties: a name, and a value. The Name property is simply a string that identifies the tag. The Value property of a Tag object is what makes tags so flexible and useful. The Value property takes a Variant data type, which means it can store any data type except fixed-length strings. This means you can store a wide range of information types in tags, including user-defined types. For more information about the Variant data type, see Variant Data Type.
Another interesting aspect of tags is that the Tags collection is one of the rare pieces of the Publisher object model that doesn't have a counterpart in the application's user interface. Tags are a totally programmatic feature: you can only access Tag objects through code. Unless you explicitly create an interface to expose them, such as by displaying them in a dialog box, or the user writes code to find them, end users aren't going to be aware of them at all. Which makes them an ideal place to store information you need to persist to perform programmatic tasks, but that you don't want the average, that is, non-programming, user to have easy access to.
Tags are particularly useful for storing the following general types of information:
- Publication, page, or shape attribute information that isn't already persisted in any of the available object model properties
- Variable data that is needed for running some procedure or programmatic functionality
To add a Tag object, use the Tags.Add method, which takes the Tag object name and value as parameters. The following line of code adds a Tag object named CreationDate, with a value of the current date, to the active document:
ActiveDocument.Tags.Add "CreationDate", CStr(Now)
Each Tag object has a Name and Value property. The Name property is read-only and must be unique within a given Tags collection. For example, you can't have two Tag objects named "Creation Date" in a single Shape object, but you can have multiple Shape objects that each have a single Tag object named that.
As mentioned earlier, the Value property takes a Variant data type, which means it can store any data type except fixed-length strings.
ActiveDocument.Tags("Creation Date").Value = "Today"
To remove a Tag object, simply call its Delete method:
As you can tell, adding tags and setting their values is fairly simple. So the question isn't really how to use tags, but what to use them for. What information should you store in tags? For the most part, your business processes determine the