Publisher: Formatting Text Across Multiple Text Boxes, or in the Overflow Buffer

Here's an interesting quirk in Publisher's object model. It's by design, and it makes sense if you think about it. But it may lead to some unexpected results if you don't take it into account. I didn't, and it did, so I thought I'd point it out.

First, start out with a text box that's small enough that not all the text displays:

Then, programmatically decrease the text font size:

ThisDocument.Pages(1).Shapes("Example"). _

  TextFrame.TextRange.Font.Size = 14

You'd expect that all the text in the text box would be set to the new font size, right? Instead, you get this:

All the text that was showing at the time the code ran is set to the new, smaller font size, thereby leaving space in the text box for more text to display. The additional text displayed, however, is still formatted at the previous, larger, font size.

This is actually by design. Here's why it happens:

Publisher lets you link multiple text boxes together, and automatically manages how text flows from one text box to the next. If there isn't room to display all the text in the first text box, the text flows into the second, and so on. If there's too much text to display in the final text box, Publisher stores the text in an overflow buffer. That's the case here; there's only one textbox, so any text there isn't room to display is stored in the overflow buffer.

Now, let's look at that line of code again:

ThisDocument.Pages(1).Shapes("Example"). _

  TextFrame.TextRange.Font.Size = 14

In this code, TextFrame.TextRange returns a TextRange object that represents the text currently displaying in the text box. Which does not include any of the text stored in the overflow buffer. So only the text showing in the text box at the time the code runs is resized.

To change the font size on all the text in the example above, you'd want to use the Story object. The Story object represents:

· All the text in an unlinked text frame, including the overflow buffer.

· All the text flowing between linked text frames, including the overflow buffer.

· The text in a table cell.

So, whereas TextFrame.TextRange represents the text currently displayed in a specific text box, Story.TextRange represents the entire text of that story, no matter how many text boxes (and the overflow buffer) it currently resides in. Each TextFrame and TextRange object has a Story property, which lets you access the Story object the text in it belongs to.

Here's the code again, rewritten to change the font size of all the text, both in the text box and overflow buffer:

ThisDocument.Pages(1).Shapes("Example"). _

  TextFrame.TextRange.Story.TextRange.Font.Size = 14

Note Just be aware when you set story properties, you set them for the entire story, no matter which text box it appears in. If the Story object in the above example flowed through several text boxes, the font size in each would be set to 14.

There is no object in the Publisher object model that represents the overflow buffer. Each TextFrame does have an Overflowing property, however, that indicates whether text is overflowing from that text box into the overflow buffer. (For linked text frames, of course, only the final text frame could be overflowing.)

Also, each TextFrame object also has an AutoFitText property, which lets you set how you want Publisher to deal with overflowing text:

· Allow the text to overflow

· Adjust the text frame size to fit the text

· Reduce the text size so that the it fits in the text frame