Discussion:
Change fill color of shape through code
(too old to reply)
c***@hotmail.com
2008-01-25 13:12:30 UTC
Permalink
I have been making my own master shapes. I note that I can change the
fill color of some master shapes through code using the following
logic:

Shape.FillStyle = "red"

Or whatever I have defined my style to be. It works pretty well for
our purposes. The problem is that some master shapes don't seem to
have a fill color, and some that I have drawn (all of them, in fact)
don't seem to want to change color through VBA no matter what I do.
Is there something I'm missing? Thanks in advance,

David
Chris Roth [Visio MVP]
2008-01-25 15:59:56 UTC
Permalink
Hi David,

FilyStyle applies an actual style to your shape. If you want to
manipulate individual characteristics, you need to set ShapeSheet cells
via code.

If you haven't seen the ShapeSheet, select a shape, then go to Window >
Show ShapeSheet. This spreadsheet thinghy defines the behavior of a shape.

John Goldsmith has a great "getting started" article that explains more:
http://visualsignals.typepad.co.uk/vislog/2007/10/just-for-starte.html

So, to programmatically change the fill color of a shape, you need to
set its FillForegnd ShapeSheet cell. Something like this:

shp.Cells("FillForegnd").Result = 2
shp.Cells("FillForegnd").Formula = "RGB(255,0,0)"

To edit masters properly, you need to start a sort of editing session:

Dim mst as Visio.Master
Dim mstCopy as Visio.Master
Dim shp as Visio.Shape

Set mst = ...get master somehow
Set mstCopy = mst.Open

Set shp = mstCopy.Shapes(1)
shp..Cells("FillForegnd").Formula = "RGB(255,0,0)"

mstCopy.Close
Set mstCopy = Nothing
Set shp = Nothing

If your shape is a group, then setting the group's fill might not do
anything, as the sub-shapes are what need colorin'. In this case, you
can recurse through shapes vis shp.Shapes.Item()

Probably not the easy answer you were looking for...!
--
Hope this helps,

Chris Roth
Visio MVP


Register for the 2008 Microsoft Office Visio Conference!
http://www.msvisioconference.com/

Visio Guy: Smart Graphics for Visual People
http://www.visguy.com
Post by c***@hotmail.com
I have been making my own master shapes. I note that I can change the
fill color of some master shapes through code using the following
Shape.FillStyle = "red"
Or whatever I have defined my style to be. It works pretty well for
our purposes. The problem is that some master shapes don't seem to
have a fill color, and some that I have drawn (all of them, in fact)
don't seem to want to change color through VBA no matter what I do.
Is there something I'm missing? Thanks in advance,
David
David Parker
2008-01-25 22:18:37 UTC
Permalink
..and not to mention that FillForegnd swaps places with FillBkgnd when you
chose a non-solid fill....
Post by Chris Roth [Visio MVP]
Hi David,
FilyStyle applies an actual style to your shape. If you want to manipulate
individual characteristics, you need to set ShapeSheet cells via code.
If you haven't seen the ShapeSheet, select a shape, then go to Window >
Show ShapeSheet. This spreadsheet thinghy defines the behavior of a shape.
http://visualsignals.typepad.co.uk/vislog/2007/10/just-for-starte.html
So, to programmatically change the fill color of a shape, you need to set
shp.Cells("FillForegnd").Result = 2
shp.Cells("FillForegnd").Formula = "RGB(255,0,0)"
Dim mst as Visio.Master
Dim mstCopy as Visio.Master
Dim shp as Visio.Shape
Set mst = ...get master somehow
Set mstCopy = mst.Open
Set shp = mstCopy.Shapes(1)
shp..Cells("FillForegnd").Formula = "RGB(255,0,0)"
mstCopy.Close
Set mstCopy = Nothing
Set shp = Nothing
If your shape is a group, then setting the group's fill might not do
anything, as the sub-shapes are what need colorin'. In this case, you can
recurse through shapes vis shp.Shapes.Item()
Probably not the easy answer you were looking for...!
--
Hope this helps,
Chris Roth
Visio MVP
Register for the 2008 Microsoft Office Visio Conference!
http://www.msvisioconference.com/
Visio Guy: Smart Graphics for Visual People
http://www.visguy.com
Post by c***@hotmail.com
I have been making my own master shapes. I note that I can change the
fill color of some master shapes through code using the following
Shape.FillStyle = "red"
Or whatever I have defined my style to be. It works pretty well for
our purposes. The problem is that some master shapes don't seem to
have a fill color, and some that I have drawn (all of them, in fact)
don't seem to want to change color through VBA no matter what I do.
Is there something I'm missing? Thanks in advance,
David
--
David Parker
Microsoft MVP (Visio)
http://bvisual.spaces.live.com
http://www.visualizinginformation.com
Loading...