Visio Guy

Visio Discussions => Programming & Code => Topic started by: tepebox on August 25, 2021, 08:06:24 PM

Title: Title of container a shape is in
Post by: tepebox on August 25, 2021, 08:06:24 PM
Hi,

so I want to create a list of all connectors with title of the source and target they connect plus the title of the container source/target are in.

What I need:
- The list of connectors - done!
- The reference to the source/target shape and getting their title - done!
- The reference to the container source/target are in - I'm stuck...

I have a variable (object) with the source shape in it. Containerproperties should give me the reference to the container the shape is in... So I'm trying to do something like

set sourcecontainer = sourceshape.containerproperties

This works nicely.

Now I want to use it... Everything I tried to use sourcecontainer doesn't work... So i.e.

debug.print sourcecontainer.shape.title

Already a

set sourcecontainershape = sourcecontainer.shape

fails.

Any idea?
Title: Re: Title of container a shape is in
Post by: Yacine on August 26, 2021, 07:08:05 AM
Use the MemberOfContainers property of the shapes:

Sub test()
    Dim shp As Shape
   
    Set shp = ActiveWindow.Selection(1)
   
    Dim arCont As Variant
    Dim vCont As Variant
    arCont = shp.MemberOfContainers
   
    For Each vCont In arCont
        Set cont = ActivePage.Shapes.ItemFromID(vCont)
        Debug.Print cont.ID; cont.Text
    Next vCont
   
End Sub
Title: Re: Title of container a shape is in
Post by: tepebox on August 26, 2021, 08:20:14 AM
THANKS, very much appreciated... I'll test that later today and give feedback!


Thomas
Title: Re: Title of container a shape is in
Post by: tepebox on August 26, 2021, 06:07:35 PM
Thanks again, after solving some issues with variable types I managed to integrate your code into my soluiton. Perfect stuff :-)