Hello people!
Do you know how can I retrieve the data informations in the Shape Data section on the ShapeSheet of my shape thanks to a VBA macro.
Thank you for your help!
Sub bbb()
Dim sh As Shape
Dim sc As Section
' sh variable is selected shape ! Urgent shape MUST be selected
Set sh = ActiveWindow.Selection.PrimaryItem
Set sc = sh.Section(visSectionProp)
' iterate rows in Shape data section
For r = 0 To sc.Count - 1
' print row's names and values
Debug.Print sh.Section(visSectionProp).Row(r).Name, sh.CellsSRC(visSectionProp, r, 0)
Next
End Sub
Thank you Surrogate!
But if I want to work with only one cell of the Shape Data section, how could I know if the cell of the value exist ?
for check is cell exist use CellExists Property (https://msdn.microsoft.com/en-us/library/office/ff766195.aspx?f=255&MSPPError=-2147217396)
like this
sh.CellExists("Prop.row_1", 0)
Hum thank you!
But I have a problem with my cells which are string when I'm doing Debug.Print sh.Section(visSectionProp).Row(r).Name, sh.CellsSRC(visSectionProp, r, 0) . :/ :/
what kind of data placed in that cell ?
try this way
sh.CellsSRC(visSectionProp, r, 0).Formula
OMG it does work!
But if I use CellsSRC(visSectionProp, r, 0).Formula , do I use CellExist to know if a cell exist ?
Okey, I will be more precise. I would like to do this : If my shape contain a cell ( this specific cell contain a string/Formula ) so I create a other shape.
The other Shape must be create only if this specific cell.
Quote from: Miguel on March 28, 2017, 09:39:52 AM
But if I use CellsSRC(visSectionProp, r, 0).Formula , do I use CellExist to know if a cell exist ?
CellExist property only check cell is exist or not exist! Cells value for this property nevermind...
In our russian-speaking Visio forum we have topic - How to define a data type in a User-defined cell (https://translate.google.ru/translate?sl=ru&tl=en&js=y&prev=_t&hl=ru&ie=UTF-8&u=http%3A%2F%2Fvisio.getbb.ru%2Fviewtopic.php%3Ff%3D6%26t%3D801&edit-text=&act=url). You can read via google-translate service (https://translate.google.ru/)
Okey thank you man! 8)
Assuming you only want to check to see if a cell exists, syntax for code is:
Sub IsThere()
Dim dude As Boolean
Dim myShp As Shape
'In this example, it assumes that shape, Sheet.1, is the shape that we want to test.
'If the shape contains Prop.IsData row, result is true. If not, result is false
Set myShp = ActivePage.Shapes.Item("Sheet.1")
dude = myShp.CellExists("Prop.IsData", 0)
Debug.Print "Prop.IsData: " & dude
'Alternate form:
dude = myShp.CellsSRCExists(visSectionProp, 1, 0, 0)
Debug.Print "Prop.IsData: " & dude
End Sub
As Surrogate indicates, this only tells you if the cell exists, not anything about what's in it.
Wapperdude
i get personal message from Miguel
Quote from: Miguel on March 28, 2017, 12:14:32 PM
Hey, it's me again!
Sorry to bother you but I really need your help. I'm a beginner in VBA and I have to do something that it's a little hard for me even if I understand almost all.
You know, I used sh.CellExists like you said me :
Debug.Print sh.CellExists("Prop._VisDM_Feature_Serv_REQ_from", 0)
If sh.CellExists("Prop._VisDM_Feature_Serv_REQ_from", 0) Then
MsgBox "YEEEEEEAH"
End If
But the little problem is that in my window I have three TRUE! That means that my little program do this code 3 times and I dont' undersntand why
My next advice was
sh.CellExists("Prop._VisDM_Feature_Serv_REQ_from", visExistsAnywhere)
Miguel answered:
Quote
Thank you amigo!
It does work!
@Surrogate: "visExistsAnywhere" : Brilliant!!! ;)
Strange his code gives 3 responses?!?
Wapperdude.
Yes 3 reponses wapperdude!
I imported a external data source (excel array) thanks to a the function "link data to shape".
So from my External data window, I drag and drop a line in my worksheet in an shape form. And obviously, I'm using simple shape like a rectangle.
I'm working with the event Document_ShapeAdded. And when I run the program, the program works Three times! But the argument move three times too. it considers that I have 3 shape because the arguments of the event change three time. Firstly it considers my shape and considers 2 times a shape called Text Callout
I hope you understand my problem better ::) ::)
Quote from: wapperdude on March 28, 2017, 04:27:12 PM
"visExistsAnywhere" : Brilliant!!!
What is difference ? :o
Quote from: MSDN (//http://)VisExistsFlags Constants (https://msdn.microsoft.com/en-us/library/office/aa196752%28v=office.11%29.aspx?f=255&MSPPError=-2147217396)
Flags to be passed to the Shape.SectionExists property and similar properties.
Constant | Value |
visExistsAnywhere | 0 |
visExistsLocally | 1 |
@Surrogate: no difference. Didn't read fine print for cellexists. :-[
If you don't want the "Brilliant!", I'll take it back, :o, save it for another time. ;)
Wapperdude
Quote from: wapperdude on March 29, 2017, 02:20:58 PM
If you don't want the "Brilliant!", I'll take it back, :o , save it for another time. ;)
;D ;D ;D
Ok, got it. So, is it still firing 3x?
If so, one method would be to modify the code. Basically, it would check for a additional 2nd cell, which would indicate the shape has already been checked, do not check again. For example, the modification might add a User.ckd entry to User Defined section of the shape sheet. A test for this entry should happen before the current cell exists test. If new test fails, proceed with 2nd test. If new test passes, then ignore this shape. Add more code after 2nd test. If 2nd test is successful, then code should add the User.ckd entry to shapesheet. If 2nd test for cell existence failed, no need to add the User.ckd entry as this shape already fails. Hope that makes sense. Basically, you're adding a "flag" to the shape which let's the macro know the shape was previously tested and was successful, thus, no need to check again.
Wapperdude