none
Visio 2010: Set title via code for shape RRS feed

  • Question

  • How can you set the title of a swimlane from code?

    I've tried setting the User.visHeadingText property's formula but this doesn't work.  The original formula in the shapesheet is something like this:  =SHAPETEXT(Sheet.11!TheText)    What object is Sheet.11?

    Tuesday, September 13, 2011 3:29 PM

Answers

  • Sory I am coming late to the party.

    The swimlane is a group shape (actually a container) and what you are seeing is the value that is in one of the group shapes. Sheet.11 is the name of the header section of that specific swimlane. User.visHeadingText is a property in the User Defined property sections of the grouped shape. So you need to edit the text for Sheet.11. All shapes have a name of sheet.###. The name is assigned when the shape is dropped on the page.

    If you were exploring the shapesheet, Visio does not expose the text value.

    As a side note, Using Character is a bit overkill, you can just use

    Set shShape = ActivePage.Shapes.Item("Sheet.11")
    shShape.text = "New Title".

    Character is used when you want to change parts of the text. for example bold the 3rd to sixth character.

    Remember, Sheet.11 is the name of the shape in this instance, the name of the header of another swimlane will be something else. If you drop other shapes before adding the swimlane, then some other shape could be called Sheet.11 and the header of the first swimlane will have another sheet name.

    So the first thing is how are you planning on selecting the swimlane or shape you want to change?


    John... the original Visio MVP (since 1993) Visio.MVPs.org

    Monday, September 19, 2011 1:28 PM
  • Hi Ira Davis,

    Do you want to reference the visio object model? If so, please refer it on the MSDN documents:

    http://msdn.microsoft.com/en-us/library/cc160740.aspx

    I think you can iterate all the shapes and set the title of the shape via judging its original text, just like:

    If shp.Text = "original title" Then

        shp.Text = "new title"

    End If

    Hope this can give you the hint and just feel free to follow up after you have tried.

    Best Regards, 


    Bruce Song [MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    • Edited by Bruce Song Friday, September 16, 2011 6:28 AM
    • Marked as answer by Ira Davis Friday, September 16, 2011 1:14 PM
    Friday, September 16, 2011 6:27 AM

All replies

  • Hi Ira Davis,

    I tried the following code, it can set the title of the visio shape, please refer to the following macro:

    Sub Macro1()

        Dim vsoCharacters1 As Visio.Characters

        Set vsoCharacters1 = Application.ActiveWindow.Page.Shapes.ItemFromID(8).Characters

        vsoCharacters1.Text = "test"

    End Sub

    Hope this can help you and just feel free to follow up after you have tried.

    Best Regards,


    Bruce Song [MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Thursday, September 15, 2011 4:09 AM
  • Where is any of this documented?  The purpose of trying to do this through code is to create visual reports.  I need to be able to drop a set of shapes into a swimlane and set the title of the swimlane to an appropriate value. 

    I can iterate through the shapes property of the swimlane and I get two sheets, 7 and 8.  How can I determine which one of these is the right one for setting the title.  I've set a watch to look at the properties and I can't see any significant difference.

    Thursday, September 15, 2011 12:35 PM
  • Hi Ira Davis,

    Do you want to reference the visio object model? If so, please refer it on the MSDN documents:

    http://msdn.microsoft.com/en-us/library/cc160740.aspx

    I think you can iterate all the shapes and set the title of the shape via judging its original text, just like:

    If shp.Text = "original title" Then

        shp.Text = "new title"

    End If

    Hope this can give you the hint and just feel free to follow up after you have tried.

    Best Regards, 


    Bruce Song [MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    • Edited by Bruce Song Friday, September 16, 2011 6:28 AM
    • Marked as answer by Ira Davis Friday, September 16, 2011 1:14 PM
    Friday, September 16, 2011 6:27 AM
  • I guess this will have to be the way it is done.  I exhausted the SDK and object model in minutes.
    Friday, September 16, 2011 1:21 PM
  • Sory I am coming late to the party.

    The swimlane is a group shape (actually a container) and what you are seeing is the value that is in one of the group shapes. Sheet.11 is the name of the header section of that specific swimlane. User.visHeadingText is a property in the User Defined property sections of the grouped shape. So you need to edit the text for Sheet.11. All shapes have a name of sheet.###. The name is assigned when the shape is dropped on the page.

    If you were exploring the shapesheet, Visio does not expose the text value.

    As a side note, Using Character is a bit overkill, you can just use

    Set shShape = ActivePage.Shapes.Item("Sheet.11")
    shShape.text = "New Title".

    Character is used when you want to change parts of the text. for example bold the 3rd to sixth character.

    Remember, Sheet.11 is the name of the shape in this instance, the name of the header of another swimlane will be something else. If you drop other shapes before adding the swimlane, then some other shape could be called Sheet.11 and the header of the first swimlane will have another sheet name.

    So the first thing is how are you planning on selecting the swimlane or shape you want to change?


    John... the original Visio MVP (since 1993) Visio.MVPs.org

    Monday, September 19, 2011 1:28 PM
  • Thanks for the detailed and very helpful info.  When I drop a new swimlane (using the Page.DropIntoList method), the method returns the shape so I have a reference to it.  I just need to know how to determine which sheet of the swimlane shape is the correct one for setting the title.  When I run this code below, I get two sheet objects.  I used the debugger to step through the code and examine the individual sheets.  I couldn't really see any difference, at least superfically, that would allow me to distinguish between them.  I did figure out that if I set the title on the wrong one, what I was setting was the title or text propery of the swimlane itself.  The other sheet object is the header box which is the one I *do* want to set.  For now, I've created a sub to iterate throught the shapes of a swimlane object and look for one with the text set to "Function".  Once I find that shape, I set the text for it to the appropriate title.  Is there a more correct way of doing this?  It doesn't "feel" right to select the shape based on the inital text setting.

     

    Sub ShowSubShapes(ByRef Lane as Visio.Shape)

        Dim VShape as Visio.Shape

        For Each VShape in Lane.Shapes

            Debug.Print VShape.Name & vbtab & VShape.ID

        Next

    End Sub

    Monday, September 19, 2011 2:37 PM
  • In Visio, you can use the Drawing Explorer to get a feel for how to navigate the shapes.

    When a swimlane is dropped, there is no guarantee what the sheet #s are but, the order will be the same. The first one will be the lane which also covers the area behind the header and the second will be the header. If you use the Drawing Explorer, you can step through the shape tree and see which areas are selected in the drawing.

    So you should be okay with Lane.Shapes(2).Text = "New Test"

    Checking that the shape has a text value of "Function" is a good way of insuring you have the right shape, and really will not slow the process down that much, but until the next version of Visio, I am reasonably certain that it will be the 2nd shape.


    John... the original Visio MVP (since 1993) Visio.MVPs.org
    Monday, September 19, 2011 3:18 PM
  • Thanks, this is some really good info. 
    Monday, September 19, 2011 4:24 PM