Referencing VBA Modules in Stencils

Started by vojo, September 21, 2008, 02:29:21 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

vojo

Assume I have a VB module in a stencil (travels with the stencil).
When I drop the shape on page and use CALLTHIS to access a routine in the stencil module, what is the format for that?

something like callthis("<stencil name>.module1.mycoolroutine")?

aledlund

#1
Check back around the 10th, I posted some code that might help.
HTH
Al

Visio Guy Edit: see:    
Referencing module in stencil

vojo

#2
I saw that and responded. It looks like you looked at 180 degrees from what I wanted to do
It appears you did "some app/drawing instance seeking out a specific stencil"
I wanted to do "VB comes with the stenicl and available to drawing when opened"

I have since found (maybe one of your appends) that you can really do that since the VB in the stencil is not made aware to anything in the drawing.

With that, I went down the template path for now.

I do appreciate the follow up!!!!

Visio Guy

#3
Hi Guys,

I took a few minutes to look at this, because it's been awhile for me...

For some reason, I thought you had to add references from the document's VBA project to the stencil's VBA project, but this is not true. I think you only need to do this to make the stencil open with the document. My experience is that it crashes a lot. But never mind about references.

Anyway, I created a document and a separate stencil. The document is named "document.vsd". The stencil is named "some_stencil.vss"

In each document's "ThisDocument" class, I added a procedure that could be accessed via the CallThis ShapeSheet function.



'// Proc in the document's VBA project:
Public Sub LocalCallThis(shp As Visio.Shape)
  Call MsgBox("Hi, my name is: " & shp.ID, , "Code from local document")
End Sub

'// Proc in the some_stencil.vss' VBA project:
Public Sub StencilCallThis(shp As Visio.Shape)
  Call MsgBox("Hi, my name is: " & shp.ID, , "Code from stencil")
End Sub



I then linked two shapes to the procedures using a formula in the on-double-click cell of the ShapeSheet.

One shape called the code in the local document:

EventDblClick = CALLTHIS("ThisDocument.LocalCallThis")

The other shape called the code in the stencil. Notice it has an extra argument to specify the VBA project explicitly:

EventDblClick = CALLTHIS("ThisDocument.StencilCallThis","some_stencil")

Both shapes were then loaded into the stencil. The shape that calls the code in the stencil will work in any drawing that it is dropped into, as long as some_stencil.vss is open.

The shape that calls the document's code will not work in other documents, since a project isn't specified. But it does work in document.vsd since that document's VBA project has a matching procedure.

Hope this helps,

- Chris
For articles, tips and free content, see the Visio Guy Website at http://www.visguy.com
Get my Visio Book! Using Microsoft Visio 2010

Visio Guy

For articles, tips and free content, see the Visio Guy Website at http://www.visguy.com
Get my Visio Book! Using Microsoft Visio 2010

Visio Guy

And here's the example I was working with for download:
For articles, tips and free content, see the Visio Guy Website at http://www.visguy.com
Get my Visio Book! Using Microsoft Visio 2010

mac1

I'm trying to call a procedure from a right click context menu on a shape that I just dropped on the drawing.  The stencil has the code, but the drawing has the shape.  I've tried using runaddon and callthis, and both don't work.  If I manually create a reference from the drawing to the stencil, then the right click menu will work.  Can you please tell me how to create the reference programmatically, when I drop a shape onto the drawing?  I'd like to create the reference, if it doesn't already exist.

Thanks

scott

=RUNMACRO("ThisDocument.displaymsg","project_with_code")

This works when:

  • The VBA project in the stencil is called project_with_code
  • the macro is located in the ThisDocument module
  • the macro is called displaymsg

Obviously, you can change the names to whatever suits you...