Size a Visio box programatically in VB

V

VBAlan

How to size a Visio box based on its text programatically in VB? Like, make
the box bigger if there is a lot of text to be put into it, or smaller if
less text were to be put in it.
 
P

Paul Herber

How to size a Visio box based on its text programatically in VB? Like, make
the box bigger if there is a lot of text to be put into it, or smaller if
less text were to be put in it.

You can get the shape to do this for you:
either manually, or in VB
set the shape's width to
=GUARD(MAX(TEXTWIDTH(TheText), 10mm))
and the height to
=GUARD(TEXTHEIGHT(TheText,Width))
 
V

VBAlan

Thank you for the response...It works fine.

But now the code creates long boxes. So, can there be a Carriage Return in
the text when it is entered programatically after every third space, and then
size the box accordingly?
 
P

Paul Herber

Thank you for the response...It works fine.

But now the code creates long boxes. So, can there be a Carriage Return in
the text when it is entered programatically after every third space, and then
size the box accordingly?

Do you mean that you want to add a CR character after every 3rd space?
Erm, I suppose so, I don't *do* VB really but I'll guess that's a
CHR($13) or similar, whatever the syntax is. Maybe I've missed some
nuance of your intentions with thsi text.
You can set the shape's height and width to whatever you like via the
Width and height cells, in either immediate values in inches, mm etc
or you can use a formula to calculate the dimensions.
In formulae you can acces the text as TheText and you can guess how to
calculate the text width and height in the current font from the
formulae below. So you might want to set the shape's width to, say,
=GUARD(MAX(TEXTWIDTH(TheText)/2, 10mm))
which will break up your text into approximately 3 lines.
 
V

VBAlan

Paul,

After sending you the message yesterday, I started playing with the box
dimension settings and what solved my problem is exactly what you suggested
in your last message "GUARD(MAX(TEXTWIDTH(TheText)/2, 10mm))". It works
exactly as I expect it to.

Thank you very much for your help.

Best Regards,

Alan
 
P

Paul Herber

Paul,

After sending you the message yesterday, I started playing with the box
dimension settings and what solved my problem is exactly what you suggested
in your last message "GUARD(MAX(TEXTWIDTH(TheText)/2, 10mm))". It works
exactly as I expect it to.

Thank you very much for your help.

Splendid! Glad to help.
 

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