Visio VBA-Change Position Type

I generate an organization chart from an excel spreadsheet and am trying to change the position types of all shapes to "Position." Is there a way to do this using VBA code?

Thanks

Comments

  • We ran into the same problem. Here is the VBA code for Visio 2003:

    Sub Test()

    OrgChart_ChangePositionType 1, 2

    End Sub


    Sub OrgChart_ChangePositionType(intShapeNumber As Integer, intPositionType As Integer)
    ' Accesses User-defined Cells for the shape
    ' Org Chart Shapes Position Types:
    ' Executive = 0
    ' Manager = 1
    ' Position = 2
    ' Consultant = 3
    ' Vacancy = 4
    ' Assistanct = 5
    ' Staff = 6

    Dim vsoPage As Visio.Page
    Dim vsoShape As Visio.Shape
    Dim vsoCell As Visio.Cell
    Dim intCounter As Integer

    Set vsoPage = ActivePage

    'If there isn't an active page, set vsoPage
    'to the first page of the active document.
    If vsoPage Is Nothing Then
    Set vsoPage = ActiveDocument.Pages(1)
    End If

    'Set the vsoShape to the desired shape (1 thru Visio.ActivePage.Shapes.Count)
    'vsoPage.Shapes(1) is the first or topmost org chart shape
    Set vsoShape = vsoPage.Shapes(intShapeNumber)

    'Set vsoCell to the desired user-defined cell and set its formula.
    Set vsoCell = vsoShape.Cells("User.ShapeType")
    vsoCell.Formula = intPositionType

    End Sub
  • We ran into the same problem. Here is the VBA code for Visio 2003:

    Sub Test()

    OrgChart_ChangePositionType 1, 2

    End Sub


    Sub OrgChart_ChangePositionType(intShapeNumber As Integer, intPositionType As Integer)
    ' Accesses User-defined Cells for the shape
    ' Org Chart Shapes Position Types:
    ' Executive = 0
    ' Manager = 1
    ' Position = 2
    ' Consultant = 3
    ' Vacancy = 4
    ' Assistanct = 5
    ' Staff = 6

    Dim vsoPage As Visio.Page
    Dim vsoShape As Visio.Shape
    Dim vsoCell As Visio.Cell
    Dim intCounter As Integer

    Set vsoPage = ActivePage

    'If there isn't an active page, set vsoPage
    'to the first page of the active document.
    If vsoPage Is Nothing Then
    Set vsoPage = ActiveDocument.Pages(1)
    End If

    'Set the vsoShape to the desired shape (1 thru Visio.ActivePage.Shapes.Count)
    'vsoPage.Shapes(1) is the first or topmost org chart shape
    Set vsoShape = vsoPage.Shapes(intShapeNumber)

    'Set vsoCell to the desired user-defined cell and set its formula.
    Set vsoCell = vsoShape.Cells("User.ShapeType")
    vsoCell.Formula = intPositionType

    End Sub
Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

In this Discussion