BB code in posts seems to be working again!
I haven't turned on every single tag, so please let me know if there are any that are used/needed but not activated.

Main Menu

Dynamically change Shape font size

Started by anico, December 10, 2018, 05:14:57 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.


Howdy folks,

I'm trying to determine the easiest way to dynamically change the font size of shape text. I want my text to be as large possible without flowing outside the shape.

I have about 60 shapes on a page. I have the same case-statement macro assigned to double-clicking all the shapes. Depending on which shape you double click, the corresponding case executes. I use this case to populate the .Characters of my "table" (a bunch of rectangle shapes arranged like a table)  Ultimately, the values that I'm using to populate the .Characters of my table are user-inputs from a separate macro, so they can be as short as one word or as long as several sentences.

I'd like the text that populates my table to be as large as possible without overflowing out of the shapes. Is there an easier way to do this other than something like...
a. measuring the length of the string (I assume there is an easy way of counting characters)
b. assigning different font sizes to different ranges of string lengths (another case statement)
c. saving the appropriate font size as a variable, including a line in each case to set the shape's font size to that variable

Here is some code to help picture what I'm doing:

'Gets shape you double click on
Dim Sel As Visio.Selection
Set Sel = ActiveWindow.Selection
Dim shp As Visio.Shape
Sel.IterationMode = 0
Set shp = Sel.PrimaryItem

'Executes code appropriate for that shape (populates table with the correct values)
Select Case shp.Name

    Case "Shape1"
        'code here
    Case "Shape2"
        'code here
' .....
    Case "Shape60"
        'code here
End Select


Scaling text to fit a shape has two solutions.  These are done in the shapesheet, see attached. These options alter either The FontScale or the Char.Size.  Each has unique impact.

The main formulas are in the User-defined Section:  User.Option1 and User.Option2.  Option2 is probably the preferred method. 

Text wrapping in Visio is not as "friendly" as other Office apps, particularly Power Point.  So, multiple lines present a problem, as the font scaling is based upon width.  The TextTransform section has basic entries to handle TextHeight growth.

Note:  I've lost track of original source for these formulae.

Visio 2019 Pro


Visio 2019 Pro


The setatref approach is certainly more flexible and if the opp is there, use it

But, FWIW, there is another less flexible option but simpler to implement

user.linewt = width/<some value maybe original with)

lineweight = user.linewt * 1pt

same approach for font

This approach goes back 20 years in visio.

Browser ID: smf (possibly_robot)
Templates: 4: index (default), Display (default), GenericControls (default), GenericControls (default).
Sub templates: 6: init, html_above, body_above, main, body_below, html_below.
Language files: 4: index+Modifications.english (default), Post.english (default), Editor.english (default), Drafts.english (default).
Style sheets: 4: index.css, attachments.css, jquery.sceditor.css, responsive.css.
Hooks called: 199 (show)
Files included: 34 - 1306KB. (show)
Memory used: 1056KB.
Tokens: post-login.
Cache hits: 13: 0.00164s for 26,764 bytes (show)
Cache misses: 2: (show)
Queries used: 16.

[Show Queries]