Visio Guy

Visio Discussions => Programming & Code => Topic started by: DJozef87 on October 21, 2011, 08:47:07 AM

Title: Change Fill Shape Color
Post by: DJozef87 on October 21, 2011, 08:47:07 AM
Hello guys,

I know that's a very stupid question but I try all the examples that I found and it didn't work
I want change the fill color of a selected shapes, I try to change the value of FillForegnd and FillBkgnd Cells but it didn't work !!


Dim shp As Visio.shape
For Each shp In ActiveWindow.Selection
'change the color
Next
Title: Re: Change Fill Shape Color
Post by: DJozef87 on October 21, 2011, 09:02:19 AM
It's a problem in my Stencil because when I try shp.Cells("Fillforegnd") = 2 with a shape from another Stencil It works !
Title: Re: Change Fill Shape Color
Post by: Jumpy on October 21, 2011, 09:27:57 AM
Maybe you have a protection activated? Or Guard function in the cell?
Use shp.Cells("Fillforegnd").FormulaForce = 2 or sth. like that
Title: Re: Change Fill Shape Color
Post by: DJozef87 on October 21, 2011, 12:09:48 PM
The problem is that it works with shp.Cells("LineColor") but it not works with Fillforegnd and FillPattern cells and I really need to set values in these two cells... I tried with .FormulaForce and I tried with .Result but it doesn't work !
Title: Re: Change Fill Shape Color
Post by: Jumpy on October 21, 2011, 12:56:26 PM
Quote from: DJozef87 on October 21, 2011, 12:09:48 PM
The problem is that it works with shp.Cells("LineColor") but it not works with Fillforegnd and FillPattern cells and I really need to set values in these two cells... I tried with .FormulaForce and I tried with .Result but it doesn't work !

Do you get an error or is it only, that nothin happens?
Have you looked in the shapesheet, if the cells have new values and they only don't get displayed?

Could you post your code and upload one of those shapes, so we can look in it's shapesheet and try to reproduce your problem?
Title: Re: Change Fill Shape Color
Post by: DJozef87 on October 21, 2011, 01:09:42 PM
the cells have new values  but nothin is displayed !! I don't know why... even If I close the document and open It the shapes have the new color values but nothin is displayed again :(
Title: Re: Change Fill Shape Color
Post by: Jumpy on October 21, 2011, 01:24:42 PM
I would realy like to see a shape. Because:
- Maybe your shape is a group and if the group has no own geometry (only subshapes) you can't change a color.
- Or geometry noshow is true
- Or ShapeTransparency is 100%
- Or the combination of FillPattern, ForegrndColor, BackgrndColor doesn't work
- Or ...
Title: Re: Change Fill Shape Color
Post by: DJozef87 on October 21, 2011, 01:49:37 PM
yes how can I get a Shape to upload it here ?  ;D
Title: Re: Change Fill Shape Color
Post by: Jumpy on October 21, 2011, 02:56:46 PM
Empty drawing *.vsd with only the shape in it.

Then when replying to this post. Below the white Edit-Box click on "Attachments and other options"
Title: Re: Change Fill Shape Color
Post by: DJozef87 on October 22, 2011, 08:54:04 AM
This particular shape don't want to display the new value of linecolor and fillpattern cells but with FillForegnd cell it works !! and Thank you for your help
Title: Re: Change Fill Shape Color
Post by: DJozef87 on October 26, 2011, 11:45:56 AM
Hello Jumpy,

So you find the problem ?
Title: Re: Change Fill Shape Color
Post by: Jumpy on October 26, 2011, 12:20:50 PM
Hello,

misted your post, where you uploaded the shape, sorry.
Will look into it this evening, when I have Visio available.

Jumpy
Title: Re: Change Fill Shape Color
Post by: wapperdude on October 26, 2011, 03:36:59 PM
Hmmmm.  Downloaded your file and it seems to be OK at first. Tried a couple more times, and it broke. This is a grouped shape, and your search is only finding the top group level.  The fill and line colors are not pushing down into the sub-shape which actually has the visible characteristics.  Is this a custom built shape? 

Basically, the displayed shape is named AgentFirstLevel. Its line color and foregnd color cells must reference the same cells in the toplevel shape, that way the values pass down from the group to the sub-shape.  Put the guard() functions around the formulas in the sub-shape.

Personal preference would be to change your formula to use rgb function instead of the color index number, e.g., shp.Cells("FillForegnd").FormulaForce = "RGB(0, 255, 0)".

HTH
Wapperdude
Title: Re: Change Fill Shape Color
Post by: DJozef87 on October 30, 2011, 05:46:59 PM
Hi wapperdude,

yes this is a custom built shape :)
I understood your explanation but I not the point around guard fontion ... if I use this fonction can I change the color without problems? and how I can use it!?
Title: Re: Change Fill Shape Color
Post by: vojo on October 30, 2011, 09:02:35 PM
Hi...not to put a damper on this thread....but you guys realize you dont need VBA to do this, right

see below

right click the blade.....pick a category, say FC....watch the ports change color

The bottom has some other stuff about enabling/disabling connection points.....dont mind this stuff

Both shapes have  NO VBA at all.
Title: Re: Change Fill Shape Color
Post by: wapperdude on October 30, 2011, 09:56:45 PM
The point around the guard function was to prevent the formula from getting clobbered, say, someone using the UI to change the color.  It is strictly optional.  All you do is enclose your formula with guard(your formula).

Since this is a custom shape, you could build the color change into the shapesheet as Vojo suggests. 

If your search macro is looking to change any and every shape, some of which may be simple shapes, others may be grouped like this one, then your code may need more developing such that when a grouped shape is identified, a sub-loop may be necessary to traverse the shapes within the group as the color will not always push down.

Wapperdude