fill a shape with text

M

mike

I am writing a VB6 add-in to fill a shape with text - but not have the
shape expand size or have the text overflow the edges of the shape. I
figured that I could get the area of the shape with AreaIU, and then
would have to do some fancy calculations based on the font face, size,
line spacing, etc. to get a general number of characters that would
basically fill the shape. Is there any easier way to do this? Any
'overflow' property or something of a shape so that I can truncate text
that is overflowing the borders? Thanks.
 
M

Mark Nelson [MS]

This is something I've been wanting to do for some time, but there is no
good way to do this.

Text is placed into the text block of a shape, not its geometry. AreaIU
gives you the area enclosed by geometry. For the text area, look at the
TxtWidth and TxtHeight cells. These are equal to the overall width and
height of the shape in many cases.

It is possible to create a routine that iteratively determines how much text
will fit in the shape. Add a User-Defined cell to the shape and insert a
formula to calculate the actual text height:

=TEXTHEIGHT(TheText,TxtWidth)

Then in your routine place one character from the full string as the shape
text. Check to see if the calculated text height is greater than the
TxtHeight cell (or shape Height). If not add another character and check
again. This will accomplish the task, albeit very inefficiently. Expect
performance to suffer here.

If you do want to just guess, Visio 2003 has a Left( ) function that will
truncate a string after a specified number of characters. Put your text
into a User-Defined cell or Custom Property and then insert a text Field
with the custom formula:

=LEFT(Prop.MyText,10)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top