Handling a Control's Events

After you add an ActiveX® control to the drawing page, you can handle the various events issued by the control—for example, if you insert a command button, you can handle its Click event. You handle a control's events by writing event procedures in the Microsoft® Visual Basic® for Applications (VBA) project of the Microsoft® Visio® drawing that contains the control, just as you would handle a Visio event.

To write an event procedure for a control

  1. In the Visual Basic Editor Code window for ThisDocument, select the control from the Object box.
  1. Select the event you want to handle from the Procedure box.
  1. Fill in the event procedure in the Code window.

For example, the following event procedure for a command button deletes a shape in the Visio drawing when a user selects the shape's name in a listbox control and clicks the command button:

Private Sub CommandButton1_Click( )     Dim visShape As Visio.Shape     If ListBox1.ListIndex >=0 Then         Set visShape = _             ActivePage.Shapes(ListBox1.Text)         visShape.Delete     End If End Sub