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?
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
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
Comments
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
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