0

I wrote a macro in Visio to retrieve the value for the shape property field index, but the row value keeps changing from shape to shape (sometimes 5 and sometimes 8). However, I can't find a way to replace the value 5 in CellsSRC with a solution that focuses on the row name rather than the row value. Any suggestions how I can find the value for the property "Index"?

This is my macro:

Sub Select_Shape()

Dim vsoPage As Visio.Page
Dim vsoShape As Visio.Shape
Dim vsoLayers As Visio.Layers

Set vsoPage = ActivePage
Set vsoLayers = vsoPage.Layers
ShapeID = ActiveWindow.Selection.PrimaryItem.ID 'find shape ID

Set vsoShape2 = Application.ActiveWindow.Page.Shapes.ItemFromID(ShapeID)

index_num = vsoShape2.CellsSRC(visSectionProp, 5, visCustPropsValue).FormulaU 'retrieve index value  <-- Here is the issue 

End Sub

This is the value I am looking for:

enter image description here

Many thanks for any suggestions!

VBA Pete
  • 2,656
  • 2
  • 24
  • 39
  • 1
    I'm hoping that [this answer](https://stackoverflow.com/a/58275316/4717755) may help you. You'll have to determine exactly which property you're looking for, but the supplied debug function can help you do that. – PeterT Apr 14 '21 at 15:16
  • Thanks @PeterT. Your link got me on track! – VBA Pete Apr 15 '21 at 07:53

1 Answers1

0

I ended up solving the issue by calling the value of the cell, which is called "Prop._VisDM_Index", directly:

Sub Select_Shape()

Dim vsoPage As Visio.Page
Dim vsoShape As Visio.Shape
Dim vsoLayers As Visio.Layers
Dim cel As Visio.Cell

Set vsoPage = ActivePage
Set vsoLayers = vsoPage.Layers

ShapeID = ActiveWindow.Selection.PrimaryItem.ID
Set vsoShape2 = Application.ActiveWindow.Page.Shapes.ItemFromID(ShapeID)

Call Deselect_layers

shape_value = vsoShape2.Cells("Prop._VisDM_Index").FormulaU
vsoLayers.Item(shape_value).CellsC(visLayerVisible).FormulaU = "1"

End Sub
VBA Pete
  • 2,656
  • 2
  • 24
  • 39