Home > database >  How to create a VISIO document using vb.Net and Position Belt
How to create a VISIO document using vb.Net and Position Belt

Time:12-12

I want to put the person's name into the Position Belt shape, but I can't figure out how to make the person's name appear.

    Private Sub Button4_Click(sender As Object, e As EventArgs) Handles Button4.Click
        Dim visApp As New Visio.Application With {
            .Visible = True
        }
        Dim vdocOrgChart As Visio.Document = visApp.Documents.Add("Organization Chart.vst")
        Dim vdocShapes As Visio.Document = visApp.Documents("ORGBLT_M.vssx")
        Dim vmstPositionBelt As Visio.Master = vdocShapes.Masters.ItemU("Position Belt")
        Dim vapPage As Visio.Page = visApp.ActivePage
        Dim vshpJohnDoe As Visio.Shape = vapPage.Drop(vmstPositionBelt, 5, 5)
        vshpJohnDoe.Name = "John Doe"
        vshpJohnDoe.NameU = "Johnny"
        vshpJohnDoe.Text = "Wheel Reinventor"
    End Sub

Here's what I get:

enter image description here

It may sound really simple, (and it probably is), but I don't want "Name" to appear in the org chart, I want "John Doe" to appear.

<>

CodePudding user response:

Found the solution myself (with a little help from Google).

   Private Sub Button4_Click(sender As Object, e As EventArgs) Handles Button4.Click
        Dim visApp As New Visio.Application With {
            .Visible = True
        }
        Dim vdocOrgChart As Visio.Document = visApp.Documents.Add("Organization Chart.vst")
        Dim vdocShapes As Visio.Document = visApp.Documents("ORGBLT_M.vssx")
        Dim vmstPositionBelt As Visio.Master = vdocShapes.Masters.ItemU("Position Belt")
        Dim vapPage As Visio.Page = visApp.ActivePage
        Dim vshpJohnDoe As Visio.Shape = vapPage.Drop(vmstPositionBelt, 5, 5)
        vshpJohnDoe.Name = "John Doe"
        vshpJohnDoe.NameU = "Johnny"
        vshpJohnDoe.Text = "Wheel Reinventor"
        Dim intSect As Integer = Visio.VisSectionIndices.visSectionProp
        If vshpJohnDoe.SectionExists(intSect, Visio.VisExistsFlags.visExistsAnywhere) Then
            For iRow = 0 To vshpJohnDoe.RowCount(intSect)
                If vshpJohnDoe.CellsSRCExists(intSect, iRow, Visio.VisCellIndices.visCustPropsValue, Visio.VisExistsFlags.visExistsAnywhere) Then
                    Dim vcLabelCell As Visio.Cell = vshpJohnDoe.CellsSRC(intSect, iRow, Visio.VisCellIndices.visCustPropsLabel)
                    Dim vcValueCell As Visio.Cell = vshpJohnDoe.CellsSRC(intSect, iRow, Visio.VisCellIndices.visCustPropsValue)
                    Dim strPrompt As String = vcLabelCell.RowNameU
                    If strPrompt = "Name" Then
                        vcValueCell.Formula = Chr(34) & "Johann Doe" & Chr(34)
                    End If
                End If
            Next
        End If
    End Sub

CodePudding user response:

As @Surrogate points out you probably don't want to change the name of the shape (from it's original "Position Belt"). The text for that name field is stored in a subshape but set from Shape Data in the top level group shape, as you discovered.

For dealing with named cells it's easier to use name syntax rather than SRC syntax. So here's a VBA example that might be helpful:

Sub ChangeName()

Dim vmstPositionBelt As Visio.Master
Dim vapPage As Visio.Page
Dim vshpJohnDoe As Visio.Shape

Set vapPage = ActivePage
Set vmstPositionBelt = vapPage.Document.Masters.ItemU("Position Belt")

Set vshpJohnDoe = vapPage.Drop(vmstPositionBelt, 5, 5)

Const NAME_CELL As String = "Prop.Name"

If vshpJohnDoe.CellExistsU(NAME_CELL, Visio.VisExistsFlags.visExistsAnywhere) Then
    vshpJohnDoe.CellsU(NAME_CELL).FormulaU = "=""Alan"""
End If

End Sub

CodePudding user response:

vshpJohnDoe.Name = "John Doe" vshpJohnDoe.NameU = "Johnny"

These lines are changes local name (Name) and universal name (NameU) of shape (vshpJohnDoe).

but I don't want "Name" to appear in the org chart

There is some sub-shape's text!

  • Related