Sizing Shapes to Text
Published Aug 26 2018 03:13 AM 662 Views
Brass Contributor

First published on MSDN on Aug, 15 2006

In a previous post, we saw how to use the ShapeSheet to resize text based on a shape’s size.  A related question we sometimes hear is how to make a shape automatically resize to contain its text.  Visio includes some shapes that resize based on their text.  Go to File > Shapes > Visio Extras > Callouts and try out the shapes near the top of the stencil.  Let’s see how to build this into a shape.

People often want to fit more text into flowchart shapes.  We can make the text smaller for shapes that cannot fit all the text, but this sometimes makes diagrams difficult to read.  In other cases, it is OK to resize shapes based on the amount of text they contain.  Let’s say we have this piece of a process flowchart.

 

 

 

The size of the Document shapes is unimportant, so we can create a formula to control the height of the shape.  Select the shape and open its ShapeSheet by choosing Window > Show ShapeSheet.  Visio opens a new window that shows the properties that drive the shape’s behavior.

 

 

 

The shape is taller, but the text still doesn’t fit right.  In this case, the Document shape is designed to keep the bottom of the text block above the rounded part of the shape, preventing it from being obscured.  We can just add a little buffer to the height of the shape.

 

 

 

But if the shape is resized manually by adjusting the green handles shown when the shape is selected, the formula will be lost.  We want the shape to always be at least as tall as the text it holds.  We can use the SETATREFEXPR formula to “pick up” the height that is set by manipulating the green handles.  Then, use MAX to compare that to the height from the formula above and use the larger of the two.

 

 

 

The shape still looks the same, but now if we resize the height manually, the formula is not lost.  And if we try to make the shape smaller, Visio only allows it to shrink small enough to contain all the text.

If this formula were applied to all Document shapes, each one would be a different size based on the amount of text it contains.  We can add a condition that keeps the shape at least as large as it was originally.  With this, shapes may resize larger but never smaller.  Another MAX condition ensures that Visio chooses the largest of the original size (0.75 in.), the calculated size and the manually set size.

 

 

 

The SETATREF trio of functions can be a little tricky to learn, but contain a lot of power for building formulas that interact well with manual changes made through Visio’s user interface.  More on these in a future post.

 

 

2 Comments
Co-Authors
Version history
Last update:
‎Nov 08 2021 04:59 PM
Updated by: