I have managed to select the objects by their fill color as well as the text. However, my major goal is to select them both by text and color simultaneously. I have a situation as you can see below:
I used the following code to place two elements with the text end AA and AB
Sub textsort()
Dim DiagramServices As Integer
DiagramServices = ActiveDocument.DiagramServicesEnabled
Dim ViPage As Page
Set ViPage = ActiveDocument.Pages("SLD")
Dim vShp As Visio.Shape
Dim subShp As Visio.Shape
Dim sel As Visio.Selection
For Each vShp In ViPage.Shapes
For Each subShp In vShp.Shapes
Select Case True
Case subShp.Characters.Text Like "*AA**"
ActiveWindow.Select vShp, visSubSelect
vShp.Cells("PinY").Formula = "780mm"
vShp.Cells("PinX").Formula = "180mm"
' iterate other conditions
Case subShp.Characters.Text Like "*AB**"
ActiveWindow.Select vShp, visSubSelect
vShp.Cells("PinY").Formula = "780mm"
vShp.Cells("PinX").Formula = "250mm"
End Select
Next subShp
Next vShp
End Sub
but I would like to have all of the elements, which have the same color filled exactly in one row.
I could use the formula like this:
If subShp.CellsU("FillForegnd").FormulaU = "THEMEGUARD(RGB(0,0,255))" Then 'BLUE
ActiveWindow.Select vShp, visSubSelect
Debug.Print vShp.ID & " - " & vShp.Master.Name
ActiveWindow.Selection.Align visHorzAlignNone, visVertAlignTop, False
vShp.Cells("PinY").Formula = "830mm"
ActiveWindow.DeselectAll
End If
which brings all the elements to one row located at Y=830mm, but the problem is, that I need the elements sorted alphabetically. Therefore I though, that catching the value with the text ending at AA (the very first from the left) would help me to achieve this goal since I know how to move all of them to the same row.
I've raised this question here: VBA Visio - autoorder items by their value (alphabetically)
What I exactly need is:
- Select & move object which text ends at i.e. "AA" like I did by using the code above
- Select all the objects, which have the same fill color as the object ending at AA and move them to the same row where the first object is located
Since I know, that every single shape includes the color value based within the THEMEGUARD() value like below:
CellsU("FillForegnd").FormulaU = "THEMEGUARD(RGB())
I would assume something like this: If the shape with text ends at AA then:
- Select all shapes with the THEMEGUARD(RGB()) value exactly the same as the object which text includes AA
- Move them to some example location
For this reason I found some approach here: http://visguy.com/vgforum/index.php?topic=4279.0
And prepare the code, which potentially could be useful:
Sub finalsort()
Dim DiagramServices As Integer
DiagramServices = ActiveDocument.DiagramServicesEnabled
Dim ViPage As Page
Set ViPage = ActiveDocument.Pages("SLD")
Dim vShp As Visio.Shape
Dim subShp As Visio.Shape, shpObj As Visio.Shape
Dim fcCell As Visio.Cell
Dim sel As Visio.Selection
Set fcCell = shpObj.Cells("FillForegnd")
For Each vShp In ViPage.Shapes
For Each subShp In vShp.Shapes
Select Case True
Case subShp.Characters.Text Like "*AA**"
ActiveWindow.Select vShp, visSubSelect
vShp.Cells("PinY").Formula = "780mm"
vShp.Cells("PinX").Formula = "180mm"
If subShp.fcCell > 1 Then
subShp.Cells("PinY").Formula = "780mm"
End If
End Select
Next subShp
Next vShp
End Sub
but it returns an error at the line:
Set fcCell = shpObj.Cells("FillForegnd")
Object variable or with variable not set
Anyway I am not sure it is correct, but as far as I understand the set above picks up the same FillForegnd parameters, so if it's > 1 then it means that there are other objects, which have the same color fill.
Concluding I am asking:
- Is it possible to set up a formula/condition, which would pick up all the elements which have the same color like the element with text ending at AA?
- How could I place them in one row?