locked
Set swimlane title via code RRS feed

  • Question

  • I'm trying to set the title of a swimlane via code.  I've tried setting the User.visHeadingText property's formula but this doesn't seem to work.  The actual title displayed on the swimlane remains "Function".  The formula before setting is something like  =SHAPETEXT(Sheet.14!TheText).     What exactly is the Sheet.14 object?
    Tuesday, September 13, 2011 3:49 PM

Answers

  • Ira, I'm not sure that it matters if you cycle through the Page Shapes and test on the vShape.Text.  Something like this:

    Sub ChangeTitle()
        Dim vShape As Visio.Shape
    
        For Each vShape In ActivePage.Shapes
            If vShape.Text = "Some Text" Then
                vShape.Text = "New Text"
            End If
        Next
    
    End Sub


    If your layout is static you can determine what Shape Names correspond to what shapes using a Debug.Print statement and opening the Immediate window:

        For Each vShape In ActivePage.Shapes
            Debug.Print vShape.Name & "  " & vShape.NameID & "  " & vShape.Text
        Next

    The MVP's probably have more elegant solutions.  Perhaps one will chime in.

     

     


    Steve Mack
    • Marked as answer by Ira Davis Friday, September 16, 2011 1:10 PM
    Thursday, September 15, 2011 2:10 PM

All replies

  • The hack I use when I can't find what I'm looking for in the ShapeSheets of a complex Shape cluster is to execute the actions with the Macro recorder on and then look at the code to see where the effects are taking place.  So in your case, activate the recorder and simply change the Title.  I tried it and got this:

    Sub Macro1()

        'Enable diagram services
        Dim DiagramServices As Integer
        DiagramServices = ActiveDocument.DiagramServicesEnabled
        ActiveDocument.DiagramServicesEnabled = visServiceVersion140

        Dim vsoCharacters1 As Visio.Characters
        Set vsoCharacters1 = Application.ActiveWindow.Page.Shapes.ItemFromID(11).Characters
        vsoCharacters1.Begin = 0
        vsoCharacters1.End = 8
        vsoCharacters1.Text = "Test 1"

        ActiveDocument.DiagramServicesEnabled = DiagramServices

    End Sub

    Pop in the code and you should be good to go.

    One of the MVP's here pointed me to this related link a couple of weeks ago:

    http://msmvps.com/blogs/visio/archive/2006/03/03/visio-s-most-useful-tool-the-macro-recorder.aspx

     


    Steve Mack


    • Edited by Stephen Mack Wednesday, September 14, 2011 12:10 AM
    Tuesday, September 13, 2011 8:09 PM
  • Thanks for the tip about using the Macro recorder.  I'm still left with trying to determine which one of the sheet objects associated with the given swimlane is the right one to use.  I set a reference to the swimlane I want and then iterated through the shapes property and got two sheet objects.  I can't see any difference between them that would allow me to determine which one is the "header" object.

     

    Thursday, September 15, 2011 12:40 PM
  • Ira, I'm not sure that it matters if you cycle through the Page Shapes and test on the vShape.Text.  Something like this:

    Sub ChangeTitle()
        Dim vShape As Visio.Shape
    
        For Each vShape In ActivePage.Shapes
            If vShape.Text = "Some Text" Then
                vShape.Text = "New Text"
            End If
        Next
    
    End Sub


    If your layout is static you can determine what Shape Names correspond to what shapes using a Debug.Print statement and opening the Immediate window:

        For Each vShape In ActivePage.Shapes
            Debug.Print vShape.Name & "  " & vShape.NameID & "  " & vShape.Text
        Next

    The MVP's probably have more elegant solutions.  Perhaps one will chime in.

     

     


    Steve Mack
    • Marked as answer by Ira Davis Friday, September 16, 2011 1:10 PM
    Thursday, September 15, 2011 2:10 PM
  • Thanks, I've been doing that (cycling through the shapes that are members of the swimlane).  I guess I could just test which sheet has a title of "Function" but this is a miserable solution.  Thanks for your help, though. 

    Thursday, September 15, 2011 3:59 PM
  • Ira, Right.  I'm not sure what your end objective is.  But you could also rename your swim lane Shapes via code with contiguous numbering, e.g., swimtext1, swimtext2 to make the mapping easier.  Coupling with static Shape names would decouple the mapping from the changeable Text Value property.

    You could also add your swim lane Shapes to their own layer.  I.e., macro record the layer selection and then operate on the Shape text by For Each'ing the Shapes after the Selection code.


    Steve Mack
    Thursday, September 15, 2011 4:39 PM
  • I'm trying to create visual reports.  One example might be to get a list of servers in a location (remote site) and drop them in a swimlane titled with the site name.  I've got modules that can create the swimlane, size it, drop in the shapes, attach data to the shapes, etc.  I just need to set the swimlane title.  I could have done it manually but I was working on creating templates so others in my organization could open a template, set a few properties and generate the report. 

     

    Thursday, September 15, 2011 4:56 PM
  • Swimlanes are a special case of containers. Containers were introduced in v2010 and there have been numerous articles on them over on the Insight Blog.

    http://blogs.msdn.com/search/searchresults.aspx?q=containers&sections=6406

    There is also some demo code on David Parker's site

    http://davidjpp.wordpress.com/2009/09/07/visio-2010-containment-and-cross-functional-flowcharts/

    and Chris Roth's site

    http://visguy.com/vgforum/index.php?topic=2474.msg10853#msg10853

     

    hth,

    al


    If this answer solves your problem, please check Mark as Answered. If this answer helps, please click the Vote as Helpful button. Al Edlund Visio MVP
    Friday, September 16, 2011 1:14 AM