VBA in stencil master

Started by liam, October 17, 2013, 10:26:50 AM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

liam

Hi,

I'm pretty new to Visio and I'm trying to create a stencil with some smart shapes.

In particular I'd like to create a shape that has a variable number of connection points depending upon its size. What I'd like to do, if possible is use the EventXFMod event to call some VB code that then adds / removes some lines in the shapesheet ?

Is this possible ? Is it even possible to have a shape in a stencil with embedded VBA code, since a document created using the stencil is not the same as the stencil document so the VB macro / module doesn't seem to be visible ?

Any help would be greatly appreciated.

Liam.

Jumpy

Using CallThis-Function in the ShapeSheet it is possible to start macro in stencil, even if the VBA project of the stencil is not known in the document of the drawing. But RunMacro function won't do that.

I would not use EventXFMod to start a macro because that event fires so often. If you wan't to react to changes of the width for example u could create a user defined cell with sth. like this:

=Callthis("MyMacro","MyVBAProject")+DEPENDSON(Width)

Because of Dependson, callthis is used whenever the width changes.

Paul Herber

There is another way, no macros, just effectively hides connection points outside the shape's area.
Example attached.
Electronic and Electrical engineering, business and software stencils for Visio -

https://www.paulherber.co.uk/

liam

Thanks very much for the replies, both very useful.

What I'm not sure of now with the first solution is that none of the following seem to do anything;

=Callthis("MyMacro","MyVBAProject")+DEPENDSON(Width)
=Callthis("MyMacro","MyVBAProject.vss")+DEPENDSON(Width)
=Callthis("MyVBAProject.TheModule.MyMacro","MyVBAProject")+DEPENDSON(Width)

This works in the immediate window when MyVBAProject is active

MyVBAProject.TheModule.MyMacro

But when another project is active the same call results in "Runtime Error 424: Object required."

Thanks again for the help - this is all very new to me. 

Jumpy

There are some threads here how to call your macro in stencil with callthis.

What normally works is Callthis("myMacroname","myProjectname") where myMacroname in unique in the VBA-project (no other similar named macros in other units of the project). If there are similar named macros you have to add the name of the unit, for example ThisDocument.myMacroname or MyMacroBas.myMacroname.
MyProjectname is the name of the name of the VBA-Project and that is normaly the name of the stencil without the .vss.

What is important with Callthis is, that it calls the macro with a reference to the shape. So your macro has to plan for that and needs for example the following body:


Public Sub MyMacroname (shp as Visio.Shape)
  'You need a variable (here called shp) in the parameters of the macro
  'to store the reference to the calling shape
  'You can use it to do sth. with the shape
End Sub


Here about Callthis:

http://msdn.microsoft.com/en-us/library/office/ms406651%28v=office.12%29.aspx