0

I would like to select the objects by the color.

So far I did something like this:

 If Vshp.CellsU("FillForegnd").FormulaU = "RGB(128,128,128)" Then
 sel.Select Vshp, visSelect
 End If

But I see no reaction at all.

enter image description here

I picked it from here:

Visio change color of all child elements using VBA

and here:

VBA Change the Color of a Rounded Rectangle in Visio

Is there any way of how I could pick up the shapes by their exact RGB colour?

UPDATE:

With the following approach:

 If Vshp.Shapes(4).CellsU("FillForegnd").FormulaU = "RGB(128,128,128)" 
 Then
 sel.Select Vshp, visSelect
 End If

I receive the following error:

Invalid Sheet identifier

Pointing out the line: If Vshp.Shapes(4).CellsU("FillForegnd").FormulaU = "RGB(128,128,128)"

The following threads: "Shape.ConnectedShapes method (Visio)" example from Microsoft site give "Invalid Sheet Identifier" error http://visguy.com/vgforum/index.php?topic=9713.0 Weren't helpful for me

UPDATE II:

I realized, that the subshape cannot be .Shape(4), because it's the text. I just need to know how to read the Drawing explorer window, because I see multiple of the same shapes in my layer and I have no clue which one should correspond to the Cabinet(Fibre Schematic).2125, or alternatively could I pick them up by name?.

enter image description here

UPDATE III

After searching the solution I found a nice hint here:

http://visguy.com/vgforum/index.php?topic=7577.0

but unfortunately it doesn't work with the manner I would like to apply:

The current code:

 For Each subshp In vShp.Shapes
 If subshp.CellsU("FillForeground").FormulaU = "RGB(128,128,128)" Then
   ActiveWindow.Select subshp, visSubSelect
   End If
 Next subshp

Throws the error:

Unexpected end of file

At the line:

   If subshp.CellsU("FillForeground").FormulaU = "RGB(128,128,128)" Then
Geographos
  • 827
  • 2
  • 23
  • 57
  • In your case you must check sub-shapes color! You really need select few sub-shapes wih line `sel.Select Vshp, visSelect`? – Surrogate Apr 26 '23 at 16:45
  • I need to select a few whole shapes (including sub-shapes) in one line, but I guess, selection all sub-shapes by their colour can be good. – Geographos Apr 27 '23 at 08:09
  • At your picture with **Drawing Explorer Window** you have a sort by layer view in the diagram. there is another shape view, where you can see the shape and its children – Surrogate Apr 28 '23 at 08:26
  • The only thing I can see it's right-click and layer properties. I cannot sort the layer by its objects therefore I am not aware of other shapes than the text (.Shapes(4)). – Geographos Apr 28 '23 at 08:36

2 Answers2

1

I need to select a few whole shapes (including sub-shapes) in one line, but I guess, selection all sub-shapes by their colour can be good

IMHO selection of sub-shapes in not good idea!
Hope these gif-animations can explain difference.

  1. Align selected shapes Align selected shapes
  2. Align selected sub-shapes Align selected sub-shapes

Even in we select all shape with some color. enter image description here How we can align them ALL?

you can explore the contents of the group using the Drawing Explorer window
Drawing Explorer window


If subshp.CellsU("FillForeground").FormulaU = "RGB(128,128,128)" Then

Por this purpose better use ResultStr property. With syntax like
If subshp.CellsU("FillForeground").Resultstr(visNone) = "RGB(128,128,128)"
This picture show difference of representation Formulas in ShapeSheet (FormulaU in VBA) and Values (ResultStr).
Formulas vs Values

Themes in MS Visio are most ugliest feature.
Themes If you apply som Theme and Shapes changed their fill colors, but in ShapeSheet in this cell you can see constant in Values or Formulas representation!!!

Surrogate
  • 1,466
  • 2
  • 11
  • 13
  • Yes, but so far I just need some way of selecting them by color. – Geographos Apr 27 '23 at 12:45
  • I don't think about aligning them, but move them to the top for example. If I could have them selected, I could think about another approach leading to sort the whole schematic shaps alphabetically by the text (Shapes(4)). – Geographos Apr 27 '23 at 16:19
  • Updated my query, as I found a new hint. – Geographos Apr 28 '23 at 10:27
  • I prefer [system Visio colors](https://forumimage.ru/uploads/20160221/145608220051857697.png) (color number in [range 0-23](https://learn.microsoft.com/en-us/office/vba/api/visio.visdefaultcolors)). I dont like use RGB colors, because it have [delimetres problem for non-English languages](https://visio-getbb-ru.translate.goog/viewtopic.php?f=5&t=844&_x_tr_sl=ru&_x_tr_tl=en&_x_tr_hl=ru&_x_tr_pto=wapp). – Surrogate Apr 28 '23 at 12:05
  • It doesn't matter which type of colors it could be, the problem is, that I can't select any object with the color. – Geographos Apr 28 '23 at 12:19
0

Indeed, unlike the previous answer, you would be able to select the whole shape by its sub-shape.

Basing on this thread: http://visguy.com/vgforum/index.php?topic=7577.0

We are able to select any subshape falling inside the shape, but also the shape by the subshape properties.

For Each vShp In VPage.Shapes
 For Each subShp In vShp.Shapes
  If subShp.CellsU("FillForegnd").FormulaU = "THEMEGUARD(RGB(191,127,255))" Then
   ActiveWindow.Select vShp, visSubSelect
  End If
 Next subShp
Next vShp

It's important to pick up the color straight from the formula presented in the ShapeSheet design

enter image description here

Once used in he manner as above, we are able to select just the particular part of our drawing, which shapes include the subshapes with this colour.

enter image description here

Geographos
  • 827
  • 2
  • 23
  • 57