Inserting formatted text and tables into Visio

Started by Yacine, November 22, 2023, 07:50:54 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.


I just had to insert a table and some formatted text - by code - into a drawing and surprise ... whilst inserting drawings in Word, Powerpoint and Excel is absolutely easy, the other way around showed to be quite difficult.

Formatted text

Ideal solution - HTML/CSS

Idealy I would have a shape (or control element) for which I could set the text property with HTML tags eg "Hello <b>cruel<\b> World!" and it would render it properly.
There is no genuine solution for that.
You could use Microsoft's Web Control - very nice, but not when you work on a "work" computer, where your IT has secured every bit of software and even such a simple operation as displaying html content is blocked.

MS Word

Next option would be to use MS Word. Either format directly your code with VBA - cumbersome with all the text runs - or write an HTML file, open it in Word, then use the Clipboard to transfer your text to Visio. That's "going through a horse's ass to get to its mouth".

Formatting in Visio

Practically unthinkable. Specially coming from another environment - external code, database, etc.


Unlike formatted text, there are easier options to insert tables.


The obvious solution and probably the most reasonable one. I'm just missing a proper macro library for handling embedded excel objects, but that's just a matter of 2-3 days of diligent development.

A visio table shape
A little less obvious, but very promising.
Set up a table shape as group, containing shapes as table cells.

Just to list up some features:

  • Set up the number of rows and columns by the means of props of the table shape. Hiding the unwanted cells.
  • Name the sub-shapes properly so as to address them by their coordinate e.g.: cell_shp = table_shape.Shapes('"Cell_B3"). Setting the formats and contents of the cells is then easy.
  • Column width bound to control points of the table shape. (With a reset feature to distribute the points evently by means of SETF/GetRef)
  • Text behavior could be set using the usual methods (Text size to adjust to size of cell or cell size adjusting to text size, hiding overflowing text and putting it in the shape's hint.)
  • Change the orientation of cells - either only the text angle or the whole cell shape.
  • Work with borders and roundings - like having arranged bubbles - something I could not do in Excel
  • Adding 3D effects to cells - not possible in Excel
  • Using groups (that Wayne doesn't need ;) ) would allow to make "smart" cells with infographics included - bars, icons, colors, etc. Either set by code or implemented is some shapesheet smartness with props.
  • Working with pictures in cells. Import the image as custom fill pattern and assign them individually by fillforegnd to the cells. (Rather difficult to manage in Excel)
  • Inserting, deleting and moving rows and columns would imply working with address of the cells. Allow negative addresses for witches.
  • Difficult - Merging cells. Probably laying a cell over others?
  • Display complex contents: e.g. complex numbers 3+5i.
  • Maybe even formulas like in Excel "A1+B2". That could even be done with plain SETF/GetRef, without macros.
  • With some code, conditional formatting.
What other options could you think of? What would you wish to get?

So far for my experiences in formatting reports in Visio. Just in case someone stumbles over similar challenges.