Hello everyone,
I'd like to know if there is a way to get the shape proprety? for exemple, is it possible to get the cost of my shape?
Like for text where I have to do: Shape.Text
Thanks for your help
shape.cells("prop.cost").resultstr("") to read it
shape.cells("prop.cost").formulau to write it.
Hi guys,
is there anyway possible I can list all the prop.* like a Key/values fashion?
I just want to see all the properties defined for a shape (considering the fact I don't know what properties could have been configured)
Hope that makes sense.
Yes, it does, but no, it is not possible :)
???
Should be possible. Requires using code. Select shape, select the shape section, loop thru the rows pulling out the names of the rows.
Let me clarify. I mean, getting property values using something like "prop.Salary" is not possible.
Getting it using the construction provided by Yacine is of course possible. Like,
shape.cells("prop.Salary").resultstr("")
Sorry. :-[ Misunderstood. :o
Thanks everyone for your feedback.
I've actually managed to achieve this, but I am not necessarily proud of the way I've done it .. :D
In this case it will show me 3 of the properties (tbh, I have 4 but I don't quite understand how to obtain the 1st one - element 0 doesn't seem to be available?)
The function will simply return a 2 dimensional array with key/values (property label/values) which can be looped through later-on.
Here's the code .. Not terrible, not great ... ;)
Private Function ListShapeProperty(ByVal shape_ As Shape) As Variant
Dim i As Integer
Dim Count As Integer
On Error GoTo End_
Debug.Print ("BEGIN")
Dim properties(1 To 3, 1 To 2) As Variant
For i = 1 To 3
Debug.Print (i)
Label = (shape_.CellsSRC(VisSectionIndices.visSectionProp, i, VisCellIndices.visCustPropsLabel).Formula)
value = (shape_.CellsSRC(VisSectionIndices.visSectionProp, i, VisCellIndices.visCustPropsValue).Formula)
properties(i, 1) = Label
properties(i, 2) = value
Debug.Print (Label & " " & value)
Next i
Debug.Print ("FINISH")
End_:
ListShapeProperty = properties
End Function
I would still recommend you follow Yacine proposal; don't use . Formula to get the value, it may cause troubles in case value is not a string or is a calculated value (uses fields for example)
But the problem is, Nikolay, that I don't know the names of the properties... So this function actually will return a 2 dimensional array with the property name & it's value. Yacine's method assumes you know the property name already (shape.cells("prop.cost").resultstr("")). Unless I totally missed the point here? :-)
@dpetrov: Your code approach is basically the way to do this.
Wrt to Section rows, it's a 0-based system, not a 1-based system.
You can find the total number of rows, and then iterate from 0 to rowcount-1. Possible code:
intRows = vsoShape.RowCount(Visio.visSectionProp)
For intCounter = 0 To intRows - 1
Debug.Print (i)
Label = (shape_.CellsSRC(VisSectionIndices.visSectionProp, i, VisCellIndices.visCustPropsLabel).Formula)
value = (shape_.CellsSRC(VisSectionIndices.visSectionProp, i, VisCellIndices.visCustPropsValue).Formula)
properties(i, 1) = Label
properties(i, 2) = value
Debug.Print (Label & " " & value)
Next intCounter
Ah thanks dude!
We seem to have ended-up with a somewhat proper solution now :-) Here is what I worked out and it seems to do the job!
Private Function ListShapeProperties(ByVal shape_ As Shape)
On Error GoTo err_
intRows = shape_.RowCount(Visio.visSectionProp)
Dim i As Integer
Dim properties() As String
ReDim properties(0 To intRows - 1, 1 To 2)
Debug.Print ("Property Name : Property Value")
For i = 0 To intRows - 1
PropName = Replace((shape_.CellsSRC(VisSectionIndices.visSectionProp, i, VisCellIndices.visCustPropsLabel).ResultStr("")), Chr(34), vbNullString)
PropValue = Replace((shape_.CellsSRC(VisSectionIndices.visSectionProp, i, VisCellIndices.visCustPropsValue).ResultStr("")), Chr(34), vbNullString)
properties(i, 1) = PropName
properties(i, 2) = PropValue
Debug.Print (PropName & ": " & PropValue)
Next i
err_:
ListShapeProperties = properties
End Function
Edit: The code has been edited as per Nikolay's post.
let me clarify. What I meant is that you get property value like Yacine wrote. Instead of:
PropValue = shape_.CellsSRC(VisSectionIndices.visSectionProp, i, VisCellIndices.visCustPropsValue).Formula
Use:
PropValue = shape_.CellsSRC(VisSectionIndices.visSectionProp, i, VisCellIndices.visCustPropsValue).ResultStr("")
I would not recommend to use "formula" to get value of a property. Use either "ResultStr" or "Result", like Yacine suggested.
Ah, I got you. Thanks folks!
Oops. Good catch Nikolay. My apologies for missing that.