페이지

2011년 2월 22일 화요일

Visio 2007 Programming: Add master and change its name when new shape is added to a page

This code replace master name with its shape name.
Originally master is named like master.. The following code changes the name, master. to shape name such as Square, Pentagon, and etc.

Private Sub Application_ShapeAdded(ByVal Shape As Microsoft.Office.Interop.Visio.Shape) Handles Application.ShapeAdded

Dim strShapeName As String = ""
Dim nCount As Integer

Dim nMasterCnt As Integer
Dim tempMaster As Visio.Master
Dim tempMasterName As String

' Check whether a same type of shape is already added
' If a same type of shape exists, the name of newly added shape will
' ShapeName.Number. The period mark will be used to determine
' the duplication of shapes and the number represents
' the total number of shapes in the document
strShapeName = Shape.NameU

' Place newly added shape to the stencil as a master
vsoStencil.Drop(Shape, 1, 1)

' Set name for newly added master
' Get the number of masters in the stencil
nMasterCnt = vsoStencil.Masters.Count
For i = 1 To nMasterCnt
tempMaster = vsoStencil.Masters.Item(i)
tempMasterName = tempMaster.Shapes.ItemU(1).NameU
If tempMasterName = Shape.NameU Then
vsoStencil.Masters.ItemU(i).Name = Shape.NameU
End If
Next
End Sub

댓글 없음: