Visio Guy

Visio Discussions => Programming & Code => Topic started by: vojo on September 21, 2008, 02:29:21 PM

Title: Referencing VBA Modules in Stencils
Post by: vojo on September 21, 2008, 02:29:21 PM
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")?
Title: Re: Referencing VBA Modules in Stencils
Post by: aledlund on September 25, 2008, 03:24:55 PM
Check back around the 10th, I posted some code that might help.
HTH
Al

Visio Guy Edit: see:    
Referencing module in stencil (http://visguy.com/vgforum/index.php?topic=249.msg1075#msg1075)
Title: Re: Referencing VBA Modules in Stencils
Post by: vojo on September 26, 2008, 12:53:02 AM
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!!!!
Title: Re: Referencing VBA Modules in Stencils
Post by: Visio Guy on September 26, 2008, 11:10:20 AM
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
Title: Re: Referencing VBA Modules in Stencils
Post by: Visio Guy on September 26, 2008, 11:14:26 AM
For more on this topic, check out:    
Referencing module in stencil (http://visguy.com/vgforum/index.php?topic=249.msg1075#msg1075)
Title: Re: Referencing VBA Modules in Stencils
Post by: Visio Guy on September 26, 2008, 11:26:41 AM
And here's the example I was working with for download:
Title: Re: Referencing VBA Modules in Stencils
Post by: mac1 on November 14, 2008, 08:28:48 PM
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
Title: Re: Referencing VBA Modules in Stencils
Post by: scott on November 17, 2008, 11:06:07 PM
=RUNMACRO("ThisDocument.displaymsg","project_with_code")

This works when:

Obviously, you can change the names to whatever suits you...
Browser ID: smf (is_webkit)
Templates: 1: Printpage (default).
Sub templates: 4: init, print_above, main, print_below.
Language files: 1: index+Modifications.english (default).
Style sheets: 0: .
Hooks called: 62 (show)
Files included: 25 - 925KB. (show)
Memory used: 778KB.
Tokens: post-login.
Cache hits: 8: 0.00434s for 22,302 bytes (show)
Cache misses: 2: (show)
Queries used: 10.

[Show Queries]