none
Fill a property on shapes by vba code RRS feed

  • Question

  • Hey guys, Im on a new project in my company and I need to make some things in Visio 2016. 

    I want to write a vba code that create a property in shape data and then fill it with the container's shape name. Is there possible?

    Ive already wrote a code that creat a property "Setor" in all shapes on the page, but I need to fill this property with the name of a container the shapes are into. 

    The code that Im using is this:

    Private Sub Setorizacao()

    Dim visShape As Visio.shape
    Dim visPage  As Visio.Page



    Set visPage = ActivePage

    For Each visShape In ActivePage.Shapes
       
       If visShape.CellExists("LockWidth", False) Then
       
       Call InitSetor(visShape)
       
       End If
       
       Next
       
       
               
    End Sub

    Sub InitSetor(ByRef shape As Visio.shape)

    ' Create Prop.Setor if they don't exist; set both fields to null

        If Not shape.CellExistsU("Prop.Setor", False) Then
            shape.AddNamedRow visSectionProp, "Setor", visTagDefault
        End If
        shape.CellsU("Prop.Setor").FormulaU = ""
        shape.CellsU("Prop.Setor.Label").FormulaU = Chr(34) & "Setor" & Chr(34)
        
        
    End Sub



    Thank you in advance.
    Thursday, February 15, 2018 12:53 PM

All replies

  • Hi Lucas,

    Thanks for visiting our forum.

    Then here we mainly focus on general issues about Visio client. Since your query is more related to VBA code, I'll move your thread to the dedicated MSDN forum for Office development for better response.

    The reason why we recommend posting appropriately is you will get the most qualified pool of respondents, and other partners who read the forums regularly can either share their knowledge or learn from your interaction with us. Thank you for your understanding.

    Regards,

    Yuki Sun


    Please remember to mark the replies as answers if they helped. If you have feedback for TechNet Subscriber Support, contact tnsf@microsoft.com.

    Click here to learn more. Visit the dedicated forum to share, explore and talk to experts about Microsoft Teams.


    Friday, February 16, 2018 1:30 AM
  • Hi, Lukas !

    You need iterate via code all shapes into container ? This action you mean as FILL ?

    Friday, February 16, 2018 6:14 AM
  • Hello Lucas Taretti,

    Container is also a shape, I would suggest get the container shape first and then get try to set property for shapes in the container shape one by by.

    Here is the example,

    Private Sub Setorizacao()
    Dim visContainerShape As Visio.shape
    Dim visChildShape As Visio.shape
    Dim visPage  As Visio.Page
    
    Dim containerProps As ContainerProperties
    
    For Each visContainerShape In ActivePage.Shapes
        'confirm if the shape is a containcer shape
        Set containerProps = visContainerShape.ContainerProperties
        If Not containerProps Is Nothing Then
        'try to get shape in the contaner shape
        IDArray = visContainerShape.ContainerProperties.GetMemberShapes(visContainerFlagsDefault)
           For I = LBound(IDArray) To UBound(IDArray)
             Set visChildShape = ActivePage.Shapes.ItemFromID(IDArray(I))
             If visChildShape.CellExists("LockWidth", False) Then
             Call InitSetor(visChildShape, visContainerShape.Name)
             End If
           Next I
        End If
    Next
    End Sub
    
    Sub InitSetor(ByRef shape As Visio.shape, conName As String)
    ' Create Prop.Setor if they don't exist; set both fields to null
        If Not shape.CellExistsU("Prop.Setor", False) Then
            shape.AddNamedRow visSectionProp, "Setor", visTagDefault
        End If
        shape.CellsU("Prop.Setor").FormulaU = ""
        shape.CellsU("Prop.Setor.Label").FormulaU = Chr(34) & conName & Chr(34)
    End Sub

    Best Regards,

    Terry


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    • Proposed as answer by Terry Xu - MSFT Saturday, February 24, 2018 4:39 AM
    Friday, February 23, 2018 9:22 AM