Author Topic: changing formatting for shape text  (Read 8381 times)

0 Members and 1 Guest are viewing this topic.

RedtoGreen

  • Jr. Member
  • **
  • Posts: 17
changing formatting for shape text
« on: January 15, 2010, 08:33:52 AM »
I'm running visio 2003, making an org chart.  I have a large number of org chart shapes, with a number of different fields within each shape (name, title, nationality etc).  

What I am trying to do is change the formatting of one field (say nationality) within all shapes, using VBA code if possible (I only say VBA, as the VBA code that I have already changes the RGB background values, so would make sense to have the same code change the text formatting too).  Specifically, I am trying to change the text colo(u)r so that it is the same as the Background colour of the shape (will have to have the same RGB values).  Each shape may have a different colour to each other so it is not possible to just change the formatting to one single RGB value for the whole page(s).

Any thoughts?  I did think about using .begin and .end to select the characters, but as the length of people's names etc are different, this wouldn't work for all shapes.  I do already have some code (for something else) that searches through for specific words (French, British, Spanish etc), so perhaps this could be modified somehow?
« Last Edit: January 15, 2010, 08:53:47 AM by RedtoGreen »

Jumpy

  • Hero Member
  • *****
  • Posts: 1061
Re: changing formatting for shape text
« Reply #1 on: January 15, 2010, 09:15:03 AM »
Hello,
look here:

Visio 2003 Developer's Survival Pack

At page 147 is an example you can modify.


But when you have only one characters row in the ShapeSheet of your shapes, so all text of a shape is formated the same, you won't need a complicated solution.
Then you can directly set a formula either per VBA or the ShapeSheet in the one color cell of the characters section.
« Last Edit: January 15, 2010, 02:07:27 PM by Visio Guy »

RedtoGreen

  • Jr. Member
  • **
  • Posts: 17
Re: changing formatting for shape text
« Reply #2 on: January 18, 2010, 06:36:20 AM »
That looks like it could be useful, thanks.  Will work on modifying it now.

In another vane... is it possible to simply set the colour of the all of the text within a custom property?  So that whatever was in 'Nationality' would turn to the colour I set regardless of the actual word in the property.  (rather than having to search through for a particular word within all of the characters in the shape)

Or, perhaps use the 'invisible' property?  When I have played with this it only changes whether or not the property appears in the rightclick-properties window, but is it possible to make the property invisible within the actual shape? (not sure if that is how the property works or not).

Thanks,
RtoG

Jumpy

  • Hero Member
  • *****
  • Posts: 1061
Re: changing formatting for shape text
« Reply #3 on: January 18, 2010, 07:55:12 AM »
When you say proprety in a shape, do you mean that you can see the value of the selected propertys in the shape? In the text of the shape?

In that case you are using fields inside the text. A field is only one character long. So you only have to format only this one character.
It doesn't matter than, how long the value of the property is.

RedtoGreen

  • Jr. Member
  • **
  • Posts: 17
Re: changing formatting for shape text
« Reply #4 on: January 18, 2010, 08:10:54 AM »
That's exactly what I mean.  However, the values of multiple custom properties are in the text of each shape, so I can't just change the formatting for all of the characters, as this would change the formatting for all the text (not just the Nationality, which is what I want).  As the org chart is pretty large, I would like some sort of VBA code so I can click a cmdButton, and *only* the characters which spell "French", or "Spanish", or whatever, have their formatting changed for all shapes on the page/s.

(I'm currently working on modifying the code you gave initially, to search through for the characters that spell eg "French", and then change those characters formatting)
« Last Edit: January 18, 2010, 08:13:05 AM by RedtoGreen »

Jumpy

  • Hero Member
  • *****
  • Posts: 1061
Re: changing formatting for shape text
« Reply #5 on: January 18, 2010, 09:23:47 AM »
That won't work because when you go through all the characters of the shape you won't find for example "French", because it's not in there. There is only 1 character which represents the field which contains the "text" of the property.

What you have to do (or better what your VBA code has to do):
- Loop through all shapes.
- Look if the shape has in the custom property a value you search for, i.e. "French".
- Then go to the character which reprents the custom property and format it.

To do the last you have to look at the shapesheets of your shapes.
Look at the characters section and look at at the Textfields section and try to identify everything, so that you can implement it in your code.