Accessing custom shape texts fields

Started by aur8l, November 22, 2012, 10:19:25 AM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

aur8l

Hello,

I'm pretty new at VBA with Visio, and I can't get o understand how Visio's referecing shapes in VBA.
I created a custom shape, made of 2 predefined shapes. This custom shapes thus contains 2 text fields, that I would like to address in VBA.
Let's say I drop onto my page 2 of my custom shapes along with some other shapes. At document opening, I would like to populate 1 text field of my custom shapes, based on the content of the other text field of the custom shape.
How can I, in VBA, only get the ID of my custom shapes, and access to its text fields ?

Hope I'm clear enough in my explanations. I'm using Visio 2003.

Thanks in advance.

aur8l

Jumpy

I guess your custom shape is a grouped shape that contains 2 or more other shapes. So if you have a reference to that shape, you need to look at it's subshapes and than get teir text:

sub test (shp as Shape)
  'shp is the reference to the currently somehow selected shape
 
  Dim subshp as Shape
  For Each subshp in shp.Shapes '.Shapes is the shape's Shape collection containing all subshapes
    MsgBox subshp.Text
  Next
End Sub


If your subshapes are grouped shapes, too, then you have ti drill down even more and use above function recursive by adding the line "test subshp"

aur8l

#2
Thanks.

I figured it out, but the thing is that I want to create a macro which :
- gets a reference to all the custom shapes in the page (so the VSD can evolve without me getting back in the code)
- reads the text form the field 1 in the custom shape, for every custom shape
- refresh the values in the field 2 of the custom shape, for every custom shape

Can I count the number of instances of a certain shape in a page ?

edit : even better, can I get an array of Shape populated only with the instances of my custom shapes on ActivePage ?

edit2 : okay, I can now count the number of custom shapes using ActiveDocument.Masters(name of my custom shape)... Still can't figure out how I can iterate through all those custom shapes to retrieve the value in the field...

Jumpy

The following code iterates through all shapes on the active page:


Sub Iterate()
  Dim pg as Page
  Dim shp as Shape

  Set pg = ActivePage

  For each shp in pg.Shapes
    If IsCustom(shp) then
      CheckText shp
    End If
  Next shp
End Sub

Function IsCustom(shp as Shape) as Boolean
  IsCustom = (shp.Master.Name = "MyMastername")
End Function

Sub CheckText(shp as Shape)
  'Code like in my first post
End Sub