How to detect frames in paragraph styles

In the user interface, it is obvious if a paragraph style has a frame.

  1. The frame is visible: when you click in a paragraph of that style, you can see the frame boundaries.
  2. The frame is functional: content will wrap around the paragraph according to the settings of the frame.

Style formatted with a Frame in Word 2010

Figure 1: In Word 2007 and Word 2010, a frame displays as a dashed blue line when content inside the frame is selected

It's not so obvious in the Word object model.

The object model gives us a .Delete method to remove a frame. For example:

ActiveDocument.Styles("MyStyle").Frame.Delete

But there is no way to add a frame to a style. The .Frame property returns a Frame object whether or not the style has a frame that is visible in the user interface. From the point of view of the object model, a frame is present for all paragraph styles.

There is no obvious way to detect the presence of a Frame as the user experiences it. That is, if I want to know whether the frame for a style is visible and functional, there is nothing in the object model that tells me.

However, testing suggests that testing the .Width and .Height properties of a style's Frame give us a proxy for identifying the presence of a frame.

If the .Width and .Height of the frame equal -1, then the frame is not visible and not functional. You cannot set the .Width or .Height to -1 (you get a message saying that the measure must be between 0.5pt and 1584pt). It seems that the only way that .Width and .Height come to be -1 is if there is no visible, functional frame.

Microsoft has not documented the use of .Width and .Height as a proxy to detect whether a paragraph style has a frame. I discovered it by testing, and it has been reliable for me. YMMV, as they say.

Follow up:  One person says that this method does not work for him, but Cindy Meister provides an alternative solution: http://social.msdn.microsoft.com/Forums/en-US/worddev/thread/6a06f149-94a2-4fa0-8026-738b1c315261/