Change color of existing shape

C

Chelle

I'm fairly new to developing in VB. I have a VB program that will perform
some functions and it will also need to open and make some changes to a visio
diagram that has been created. The program will check certain conditions and
then change the color of the appropriate shapes in the diagram. What would
the code look like for doing this? How do I identify the shapes that I want
to change and then make the change?
 
D

dilettante101

Chris Roth did something neat to show how this might be done. Check it out.

http://www.visguy.com/2008/03/04/how-many-fill-colors-can-you-put-on-...

With regard to the second question, only you know which shapes you want to
play with.

al

Chelle,

Check the Color by Value option in the Edit DataGraphic dialog box.
That may be all you need. If you have more complex logic that you
have to evaluate to determine the color, you could create an auxiliary
data field whose values are generated by logic embedded in the Shape
Sheet or else from a VB function that returns a color code based on
which conditions are satisfied. Some pseudo-code for example:

If A AND B Then Return 1 (Red)
If A AND NOT B Then Returne 2 (Yellow)
If B AND C Then Return 3 (Green)

Then use those codes to assign specific colors in the Color by Value
dialog box

SteveM
 
J

Jeeban

Chelle said:
I'm fairly new to developing in VB. I have a VB program that will perform
some functions and it will also need to open and make some changes to a visio
diagram that has been created. The program will check certain conditions and
then change the color of the appropriate shapes in the diagram. What would
the code look like for doing this? How do I identify the shapes that I want
to change and then make the change?



Hi....
Retrive all the shape from the activated page.
retrive one by one shape name and compare with the name u want to change .
then retrive that single shape and do the rest.

regards
jeeban
 
J

John Marshall, MVP

One of the big powers of Visio is the smarts of the shapesheet. Control of
the colour of the shape can be done in the shapesheet. You can set the cell
that defines the colour of the shape to a formula that determines its' value
by the values of custom properties.

For example: (swiped from http://visio.mvps.org/ShapeSheet.htm)
Put this formula in the FillForegnd cell.

=Lookup(Prop.Status,"Black;White;Red;Green;Blue;Yellow")

(A formula error will occur if the custom property, in this case Status,
does not already exist.) Lookup will match the value of the custom property
Status to the list shown above. The value returned by Lookup will be a
number starting with 0 which corresponds to the position of the matched
value in the list. The list shows Visio's numbering sequence for the
colours.
If the property choices are "Warning", "Caution" and "Clear" with
corresponding colours. In the Lookup formula, replace the words "Red",
"Yellow" and "Green" with "Warning", "Caution" and "Clear". You must leave
the other items in as place holders to get the correct colour position. The
final formula would be:

=Lookup(Prop.Status,"Black;White;Warning;Clear;Blue;Caution")

John... Visio MVP

Need stencils or ideas? http://visio.mvps.org/3rdparty.htm
Need VBA examples? http://visio.mvps.org/VBA.htm
Visio Wishlist http://visio.mvps.org/wish_list.htm
 

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