Shape naming in shape sheet problems?

Started by stuman, May 18, 2009, 06:43:41 AM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

stuman

Hi, I have some custom vba code that uses logic from the name of the shape being dropped. This is not a problem but sometimes the shape name is something out of the blue like "Sheet5", whereas the normal name is "From Excel Linked". Is there anyway to stop the name from being changed by visio when it is dropped onto a sheet? I have included the vba code for when a dynamic connector is added. It works fine unless the name of the object being dropped is changed.


If Shape.Connects(1).ToSheet.Name Like "Text Input*" Then
        If Shape.Connects(1).ToCell.Name Like "Connections.Input_Text*" Then
            If Shape.Connects(2).ToSheet.Name Like "From Excel Linked*" Then
                If Shape.Connects(2).ToCell.Name Like "Connections.Input*" Then
                    pstr = PropCellName(Shape.Connects(1).ToCell.Name)
                    myFormula = "Guard(sheet." & Shape.Connects(1).ToSheet.ID & "!" & pstr & ")"
                    pstr = PropCellName(Shape.Connects(2).ToCell.Name)
                    Shape.Connects(2).ToSheet.Cells(pstr).FormulaForce = myFormula
                   
                End If
            End If
        End If
    End If


Thanks
Stu

Visio Guy

stuman,

You should probably actually stay with the "Sheet"-style naming, because it is more robust, especially as you dive into groups and do weird things.

Try checking: shp.NameID to get Sheet names.

It looks like you are trying to check the type of shape to which a connector is glued. You might try something more like this:


Dim shpConn As Visio.Shape, shpTo As Visio.Shape
Set shpConn = Visio.ActiveWindow.Selection(1)
Set shpTo = shpConn.Connects(1).ToSheet

Dim sMstName as String
If Not(shpTo.Master is Nothing) Then

  sMstName = shpTo.Master.Name

  '//...do text comparisons with sMstName to determine
  '// which kind of shpae shpTo is.

End If



For articles, tips and free content, see the Visio Guy Website at http://www.visguy.com
Get my Visio Book! Using Microsoft Visio 2010