Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm trying to find a way to get the text in a Visio shape to shrink to fit the width of the shape, otherwise leave the font at the default.

Is there a shapesheet function I can use to change the font size of the text so that it doesn't exceed the width of the shape?

Ultimately I'd like to be able to assign this when automatically building the shape using VBA, so if there's some way to get the width of text that way, maybe I can do that.

share|improve this question
up vote 1 down vote accepted

You can resize the font of the text block using automation if the text exceeds the size of the shape. I found that the following works.

Open the shape's shapesheet (Window->Show Shapesheet) and add the user section (Insert->Section->User-defined Cells). Put this formula in the value cell for User.Row_1:


After the shape text changes, get the value of the user cell. in c#:

double scale = shape.get_CellsSRC((short)IVisio.VisSectionIndices.visSectionUser, (short)IVisio.VisRowIndices.visRowUser, (short)IVisio.VisCellIndices.visUserValue).ResultIU;

Then set the font, and the TextMargins (for any that are non-zero) with the following (assuming the normal font size is 12 and the left margin is 4pt.:

shape.get_CellsSRC((short)IVisio.VisSectionIndices.visSectionCharacter, 0, (short)IVisio.VisCellIndices.visCharacterSize).FormulaU = (scale*12).ToString() + "pt";

shape.get_CellsSRC((short)IVisio.VisSectionIndices.visSectionObject, (short)IVisio.VisRowIndices.visRowText, (short)IVisio.VisCellIndices.visTxtBlkLeftMargin).FormulaU = (scale * 4).ToString() + "pt";

share|improve this answer

I don't know of a way to size text to the shape unless you change the font size, but there are ways to size shapes to the text instead of the other way around.

share|improve this answer
Yeah, my shapes can't be resized the way they're used, so the text has to just fit into the shape as it exists. Maybe that link will show me how to do it the other way...Thanks – Jon Fournier Dec 9 '09 at 17:20

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .