How do I retrieve Visio custom shape information with VBA

JonnyGold picture JonnyGold · Feb 3, 2009 · Viewed 23.7k times · Source

Using VBA, how do I retrieve custom shape information from a Visio 2003 diagram.

Answer

Jon Fournier picture Jon Fournier · Feb 3, 2009

To get custom shape information from a Visio shape:

Function GetCustomPropertyValue(TheShape As Visio.Shape, ThePropertyName As String) As String
    On Error Resume Next
    GetCustomPropertyValue = TheShape.CellsU("Prop." & ThePropertyName).ResultStr(visNone)
End Function

All this function does is uses the cellsu property on a shape to get the custom property ShapeSheet cell by name...

If you're a stickler about using the on error resume next, you can check to see if the cell exists by first checking if the cell exists:

if TheShape.CellExistsU( "Prop." & ThePropertyName , 0 ) then
GetCustomPropertyValue = TheShape.CellsU("Prop." & THePropertyName).ResultStr(VisNone)