Changing fill color using VBA not changing fill color on shape

Started by boydsminnix, June 24, 2019, 04:38:41 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

boydsminnix

Hi,

I'm using Visio standard 2013.  I'm trying to change organizational chart shapes to different colors based on an employee being Full time or Part time using VBA.  I have no issues with changing Line color, font or character size.  However, when I change the Fillforegnd the shape does not render the new color.  However, if I click on the fill button, it shows the new color but the shape itself does not.

Does anyone help please?

  Dim shp             As Visio.Shape
    Dim EE

            ActiveWindow.DeselectAll
    For Each shp In sel
        shp.Cells("Char.Font").Formula = "=FONTTOID(""Calibri"")"
        shp.Characters.CharProps(visCharacterSize) = 8
        shp.Cells("LineColor").FormulaForceU = "RGB(0,0,0)"

        If shp.CellExistsU("Prop.Employee", visExistsAnywhere) = -1 Then
            EE = Mid$(shp.Cells("Prop.Employee").FormulaU, 2, 4)
'           msg = MsgBox(EE, vbOKOnly, "Confirmaiton")
           
            If EE = "Full" Then
                shp.CellsU("FillForegnd").FormulaForceU = "RGB(255,6,20)"
            Else
                shp.CellsU("Fillforegnd").FormulaForceU = "RGB(0,255,255)"
            End If
           
        End If
    Next shp

Paul Herber

The Org-Chart shapes are grouped shapes. Using the Fill button on the toolbar affects sub-shapes as well as the top-level shape, but your code doesn't do that. Your code needs to supply fill to appropriate sub-shapes as well. Use the shapesheet editor to work out which sub-shapes you need to apply a fill value to.
Electronic and Electrical engineering, business and software stencils for Visio -

https://www.paulherber.co.uk/

boydsminnix

Thank you very much for the response.  Sorry if I am misunderstanding.  However, the fill color is updating on the shapesheet to the correct RGB in the fillforegnd field.  Am I not correctly understanding what you mean by shapesheet editor?

Paul Herber

But is it setting the fill colour in any of the sub-shapes? That's what you need to do.

Electronic and Electrical engineering, business and software stencils for Visio -

https://www.paulherber.co.uk/


wapperdude

What Paul is saying, the code will only set the color of a specific shape.  The shape you're working with is a grouped shape.  Changing the color of the group via code will not impact the look of the group because the code change is not flowing down to the necessary sub-shape.  You must identify the specific subshape and change its fill color.

Visio 2019 Pro

vojo

"flowing down" only automatically works from Human/UI context....shapesheet and VBA do NOT automatically color all
the child shapes of a group