retrieve data informations in the Shape Data section on the ShapeSheet

Started by Miguel, March 28, 2017, 06:54:40 AM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Miguel

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!

Surrogate

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

Miguel

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 ?

Surrogate


Miguel

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) . :/ :/


Surrogate

what kind of data placed in that cell ?
try this way
sh.CellsSRC(visSectionProp, r, 0).Formula

Miguel

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.

Surrogate

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. You can read via google-translate service


wapperdude

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
Visio 2019 Pro

Surrogate

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!

wapperdude

@Surrogate:  "visExistsAnywhere" :  Brilliant!!!   ;)

Strange his code gives 3 responses?!?

Wapperdude. 
Visio 2019 Pro

Miguel

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  ::) ::)


Surrogate

Quote from: wapperdude on March 28, 2017, 04:27:12 PM
"visExistsAnywhere" :  Brilliant!!! 
What is difference ?  :o
Quote from: MSDNVisExistsFlags Constants
Flags to be passed to the Shape.SectionExists property and similar properties.

Constant
Value
visExistsAnywhere
0
visExistsLocally
1

wapperdude

@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
Visio 2019 Pro