Visio shape data / user cell in shape text with multiple colors other formatting

Started by Visisthebest, January 19, 2024, 04:38:29 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Visisthebest

I am trying to see if there is a way to bind multiple user cells and shape data cells to a single text box and this is possible no problem.

The next step is I am trying to see if I can apply different colors to the different texts now showing from these user cells / shape data cells in the same shape?

Say:
User.A with the word "Green"
User.B with the word "Orange"

where I can apply the color green to the word Green and the color orange to the word Orange.

I don't seem to be able to do this, but maybe there is a cool workaround I am not aware of, another way of achieving this with the shapesheet.
Visio 2021 Professional

Surrogate


wapperdude

Visio 2019 Pro

Visisthebest

With the shapesheet, if this is possible.

The purpose is colorcoding data that is good, mediocre or bad.

Putting it in to one shape instead of several is for performance reasons, to avoid having too many shapes.

I don't think it is possible without programming, but I may be overlooking a clever workaround.
Visio 2021 Professional

Nikolay

If I understand you goal correctly, you could try to play with "character" section.
I would not do that though (may be fragile) but depends on your case of course.
A sample attached.

Visisthebest

Amazing Nikolay :D I thought this was not possible how did you do this?

I am only able to add one text field row (where I then combine multiple User.X references in to a single string) but don't know how you can add multiple rows. In the shapesheet section I do not have an option to add a row like in the User section and other sections.

Also, where is the middle string "something" coming from?

Yes the characters section is a bit fragile, but I think I can work with the limitations.

One thing I also wondered, is there a string character code which does not take up any space (so I can add some invisible padding to keep the amount of characters the same in a coloured section in the text)?
Visio 2021 Professional

Nikolay

Well I just inserted two fields, "first" and "second" (using the "insert field" command). The text "something" is just a plain text between them. You can insert as many fields as you want, that's why the command is called "insert field". Then set the color of the first field to red and then the color of the second field also to red (using the "text color" command). This added two fragments to the "characters" section.  Then in the "characters" section I have sent the color for the first fragment to be equal to "first color" property and the color of the second fragment to be equal to the "second color" property.

A common confusion here is how you insert fields. To insert more than one, you need to enter the text edit mode (i.e. start edting text and then while in the text edit, insert the fields into it). Then field is inserted into the text at your current cursor position (it does not replace the text, but is inserted into it)

Here is a video where some guy inserts multiple fields: https://youtu.be/NXwqpDojdB8?si=JsaLDaL8uf-mPBrI&t=107


Visisthebest

Thank you Nikolay yet I just select the shape then add a field, did not realize I should edit the text then add a field!

Wapperdude thank you for all the links, what I am trying to achieve will not be simple so good to get a better understanding of the Characters section (and object in code) first this is very different from HTML text with tags for text color, bold etc.
Visio 2021 Professional

Visisthebest

Found this comment in one of your posts Wapperdude very interesting:

Note, it's possible to pass more than just text.  For example, the following would pass the result of the "Len" function:
        shp.Characters.AddCustomFieldU Chr(34) & Len("NewFieldText") & Chr(34), visFmtNumGenNoUnits

Adding 'fields' is basically adding in custom formulas that write part of the content of the text box very useful.
Visio 2021 Professional

Nikolay

Quote from: Visisthebest on January 20, 2024, 07:23:42 PM
Thank you Nikolay yet I just select the shape then add a field, did not realize I should edit the text then add a field!

Yes, this is exactly the confusion. Visio developers could have done something better here for the usability.
Anyway, after you add the fields this way, and then add some formatting to them (like I said before, you can select the field fragment while editing text and change the color for the field for example), you get that "characters" section you can control:

The "THEMEGUARD" is not really important, it's only relevant if you care for themes, the whole thing can be simplified to just a direct reference to the "color" property, like "Prop.FirstColor"

Visisthebest

Thank you Nikolay, as far as I can understand from Wapperdude's linked posts and the macro recorder all this can be done from automation with code as well, or am I overlooking something not possible in code only in the UI possible?
Visio 2021 Professional

Nikolay

Hm I did not think how to do that with code tbh, I tried that using UI only.

wapperdude

In reply #4, this link: http://visguy.com/vgforum/index.php?topic=5678.msg22615#msg22615, there is Visio file that has example of both standard shapetext and field inserted text.  Working with field text is somewhat more challenging than standard text.  The file provides an opportunity to explore both. 
Visio 2019 Pro

Visisthebest

Visio 2021 Professional