Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Can't Access or Change Master Shapes Cells

Status
Not open for further replies.

SBDev

Programmer
Jul 12, 2002
12
CA
Hi Everyone,

I am very new to developing in Visio using VBA. I am currently attempting to get a Master Shape that is dropped onto a Foreground Page to match its' PinX, PinY, Width, and Height properties to a shape that already exists on the page.

I have include some simplified code to illustrate where my challenge is occurring. The Width of the shape (rectangle.5) that is already on the foreground page is returning a correct value. When the master shape is dropped onto the page the Width propery is 0 in. -- it should be 2.5 in. and I can not set it to the Width of (rectangle.5) -- I assume that If I learn the proper syntax and formating for the width, the PinX,PinY, and Height properties will be set the same way.

I do not think that I am accessing the Master Shapes cell properties correctly. It says in the "Developing Visio Solution" book that "to work with formulas of a Master,. use the PageSheet property of the object. which returns a Shape object. You can then use the Cells property of that Shape object to work with its formulas." this is not working for me.

Can you please provide some examples or some thoughts.

< code >

Dim shpObj As Visio.Shape
Dim celObj As Visio.Cell
Dim mastCelObj As Visio.Cell

Set shapeObj = ActivePage.BackPage.Shapes.Item(&quot;Rectangle.5&quot;)

' This works. celObj is set to 3.127 in.
Set celObj = shapeObj.Cells(&quot;Width&quot;)

Dim mastObj As Visio.Master

' Get the Master property of the dropped shape
'This works. mastObj is set to the name of the master
Set mastObj = Shape.Master

'This is incorrect. It is set to 0 in. It shoudl be 2.5 in.
Set mastCelObj = mastObj.PageSheet.Cells(&quot;Width&quot;)

Thank You,
:-(
 
Solved this one! I discovered that I needed to set the properties of the instance of the master shape and not the master its' self. Code sample (with hardcoded shapes for readability):

Private Sub Document_ShapeAdded(ByVal Shape As Visio.IVShape)
' When a shape is add do the following

' --------------- Target Shape and Properties ----------
' Initiate &quot;Target&quot; Object and its' properties as variables
Dim TtlTarShapeObj As Visio.Shape
Dim TtlTarWidthCell As Visio.Cell
Dim TtlTarHeightCell As Visio.Cell
Dim TtlTarPinXCell As Visio.Cell
Dim TtlTarPinYCell As Visio.Cell

' Add data to the &quot;Target&quot; Object Properties
Set TtlTarShapeObj = ActivePage.BackPage.Shapes.Item(&quot;Rectangle.5&quot;)
Set TtlTarWidthCell = TtlTarShapeObj.Cells(&quot;Width&quot;)
Set TtlTarHeightCell = TtlTarShapeObj.Cells(&quot;Height&quot;)
Set TtlTarPinXCell = TtlTarShapeObj.Cells(&quot;PinX&quot;)
Set TtlTarPinYCell = TtlTarShapeObj.Cells(&quot;PinY&quot;)

' --------------- Drop &quot;Title&quot; Shape and Properties ----------
' Initiate Drop &quot;Title&quot; Object and its' properties as variables
Dim TtlShapeObj As Visio.Shape
Dim TtlWidthCell As Visio.Cell
Dim TtlHeightCell As Visio.Cell
Dim TtlPinXCell As Visio.Cell
Dim TtlPinYCell As Visio.Cell

' Add data to the &quot;Target&quot; Object Properties
Set TtlShapeObj = ActivePage.Shapes.Item(&quot;Title&quot;)
Set TtlWidthCell = TtlShapeObj.Cells(&quot;Width&quot;)
Set TtlHeightCell = TtlShapeObj.Cells(&quot;Height&quot;)
Set TtlPinXCell = TtlShapeObj.Cells(&quot;PinX&quot;)
Set TtlPinYCell = TtlShapeObj.Cells(&quot;PinY&quot;)

' Physically change the dropped shape's dimensions.
TtlWidthCell = TtlTarWidthCell
TtlHeightCell = TtlTarHeightCell
TtlPinXCell = TtlTarPinXCell
TtlPinYCell = TtlTarPinYCell

Hope this can help someone else.

SBDev
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top