ShapeAdded Event within a stencil?

C

CNPCarl

I want code to run each time I add a new shape from a specific stencil to a
drawing so that I can open up the stencil from any drawing and use the code.

I've tried using a "Document_ShapeAdded" Sub and a "Page_ShapeAdded" Sub
saved in a stencil, but neither had any effect when I added shapes from the
stencil to a drawing.

Can you run code from a stencil when a certain event (like adding a shape to
a drawing) occurs?

Any help is appreciated. Also, does anyone have a site that talks about
events and how to use them?

Carl
 
J

junethesecond

If your macro is on the stencil,
and you wish to use Document_ShapeAdded,
the drawing to drop a shape is ActiveDocument,
so, if you put your code on ThisDocument of
the stencil, please code like,

Private WithEvents MyDocument As Visio.Document
Private Sub Document_DocumentOpened _
(ByVal doc As IVDocument)
Set MyDocument = ActiveDocument
End Sub
Private Sub MyDocument_ShapeAdded _
(ByVal Shape As IVShape)
MsgBox "MyDocument_ShapeAdded"
End Sub

If you wish to use Page_ShapeAdded,

Private WithEvents MyPage As Visio.Page
Private Sub Document_DocumentOpened _
(ByVal doc As IVDocument)
Set MyPage = ActivePage
End Sub
Private Sub MyPage_ShapeAdded _
(ByVal Shape As IVShape)
MsgBox "MyPage_ShapeAdded"
End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top