 answer to that. What information do you need to persist in a publication to complete your business tasks?
Let's take a look at a few simple examples to get you thinking about how tags can work for you.
Suppose you create a catalog of your products, including prices that are subject to change over time. You print the catalog on a desktop printer. However, you want to be sure your employees don't print the catalog for a customer once it's more than three months old. So when you finish creating the catalog, you add a document tag, called Expiration Date, and set its value to a date 90 days in the future:
ActiveDocument.Tags.Add "ExpirationDate", CStr(Now + 90)
Then, you write an event handler for opening the document. The event handler compares the value of the Expiration Date tag with the current date. If the publication is opened after the expiration date, a dialog box displays advising the user not to print the catalog because the prices may not be accurate anymore.
Note For this code to work, place this event handler in the ThisDocument object module for the publication.
Private Sub Document_Open() If CDate(ActiveDocument.Tags("ExpirationDate").Value) < Now Then MsgBox Prompt:="Prices in this catalog may be out of date." & _ vbLf & "Do not release this catalog to a customer" & vbLf & _ "without checking that prices are accurate.", _ Buttons:=vbExclamation, _ Title:="Expiration Date Passed" End If End Sub
Or perhaps you want to classify the publication you create. Suppose you're creating publications for a number of projects. You might want to add a Tag object to each publication to identify which project it's for. So you add a Tag object, named for the project, that has an initial value of "InProcess":
ActiveDocument.Tags.Add "Farble Project", "InProcess"
When the project is done, you change the value to "Complete". Then, you write a procedure that goes through your various work folders once a week and moves any publications where the tag value equals Complete to a "Completed Projects" folder.
Using the FindShapesByTag Method
The Document.FindShapesByTag method enables you to identify all shapes in a publication that contain a specific Tag object. The method returns a ShapeRange collection comprised of the shapes from all publication pages that contain a specific Tag object. This includes shapes contained in grouped shapes, as well as shapes on master pages.
The Publisher object model doesn't currently contain any methods to return Document or Page objects that contain specific Tag objects.
For example, suppose you create a book, and each chapter is a separate publication. Within each chapter you use text box shapes for a number of different functions: the main chapter text, but also side-bar stories, pull quotes, figure captions, and so on. Programmatically, there's no way to tell the function of each text box shape. But you can use tags to do exactly that. When you create each publication, add a Tag object to each text box that denotes what you're using it for. For example:
Activedocument.Selection.ShapeRange(1).Tags.Add "StoryType", "PullQuote"
Note The previous code example assigns the tag to the first shape in the ShapeRange you currently have selected in the active document. Obviously, if you only have one shape selected, then that's shape one.
Later, you decide that you want to change the font you used for all the pull quotes, and increase the font's point size while you're at it. You can quickly create a procedure that identifies all the text boxes containing pull quotes, based on the value of their StoryType tag, and makes the appropriate changes.
Note that the Documents collections contains each publication that is currently open on your computer. The following example assumes that you open each publication you want to affect.
Sub FormatPullQoutes() Dim d As Document Dim sr As ShapeRange Dim s As Shape For Each d In Documents Set sr = d.FindShapesByTag("StoryType") For Each s In sr If s.Tags("StoryType").Value = "PullQuote" Then s.TextFrame.TextRange.Font.Name = "Arial" s.TextFrame.TextRange.Font.Size = 20 En