Visio Guy

Visio Discussions => Programming & Code => Topic started by: healthNut on August 07, 2012, 04:07:46 AM

Title: How to reference a stencil's sub from a shape's user-defined Cell?
Post by: healthNut on August 07, 2012, 04:07:46 AM
After experimenting with multiple callthis and one runmacro, I can't seem to figure how to reference stencil code from a shape's User-defined Cells:

1. CALLTHIS("ThisDocument.testing") 'Works: calling the main document's sub

2. CALLTHIS("Testing.testing","POC") 'Works: calling sub in module of main document

3. CALLTHIS("ThisDocument.testing","PeopleBasics") 'Fails: trying to call the stencil's sub in ThisDocument

4. CALLTHIS("testing","PeopleBasics") ' Fails: another way to try to call the stencil's sub in ThisDocument

5. CALLTHIS("shapeMod.testing","PeopleBasics") 'Fails: trying to call stencil's shapeMod module's sub

6. RUNMACRO("ThisDocument.testing","PeopleBasics") 'Crashes

I even referenced code in past postings from visguy:
http://visguy.com/vgforum/index.php?topic=359.0 (http://visguy.com/vgforum/index.php?topic=359.0)
Title: Re: How to reference a stencil's sub from a shape's user-defined Cell?
Post by: Jumpy on August 07, 2012, 07:26:59 AM
First: You normaly can't use RUNMACRO to call code from a stencil. For this to work, you have to place a reference to the stencil in the VBA project of the drawing.

One of the nice things with CALLTHIS is, that you won't need that reference, to call macros from the stencil.
But there are a few things to know: For example, the procedure you're calling has to accept a shp as parameter and may not be a "Private Sub":


Public Sub MyTest(shp as Visio.Shape)
  MsgBox shp.Name
End Sub


And you have to use CALLTHIS in the way you tried:
CALLTHIS("testing","PeopleBasics")

Here PeopleBasic should be the name of the VBA-Project in the stencil (normaly it's the same as the stencilname). The macro testing is called. Only if there's more than one macro with the same name you need to add the name of the modul:
CALLTHIS("shapeMod.testing","PeopleBasics")

hth Jumpy
Title: Re: How to reference a stencil's sub from a shape's user-defined Cell?
Post by: healthNut on August 07, 2012, 01:43:56 PM
Thanks Jumpy for the follow up, really appreciate this. I double check my stencil call and it matches your example, can't figure out what I'm missing.

See attached snapshot of my stencil project name.
The Public sub in the stencil's ThisDocument does take a shape arg:
Public Sub testing(shpObj As Visio.Shape)       
    Debug.Print "Testing from PeopleBasics ThisDocument"   
End Sub


Tried both without the macro being called:
CALLTHIS("testing","PeopleBasics")
CALLTHIS("ThisDocument.testing","PeopleBasics")
Title: Re: How to reference a stencil's sub from a shape's user-defined Cell?
Post by: Jumpy on August 07, 2012, 02:51:54 PM
How do you aktivate the Callthis in the User defined cells? How you make sure, there is an event that fires?
Could you show a jpg of the ShapeSheet?
Title: Re: How to reference a stencil's sub from a shape's user-defined Cell?
Post by: healthNut on August 08, 2012, 06:18:38 AM
Sure, thanks for asking.
The ThisDocument.testing and Testing.testing works
None of the stencil calls work
Title: Re: How to reference a stencil's sub from a shape's user-defined Cell?
Post by: Jumpy on August 08, 2012, 07:51:33 AM
I'm out of my depth. Can't see, why it doesn't work. Just straws:

- Just to see, if Dependson fires:
Dependson(...)+Callthis(...)+Setf(Getref(User.RankListen.Prompt),"Jo")

- The stencil is open I hope

- Completly disable Macro security (for this test)

- If stencilname (without .vss) is different from VBA-project-name, try the stencilname in the Callthis

- Choose a unique name for a macro and try Callthis without the modul (only projectname and macroname)
Title: Re: How to reference a stencil's sub from a shape's user-defined Cell?
Post by: healthNut on August 08, 2012, 01:11:15 PM
Thanks for those suggestions. Appreciate your honesty too, I thought I missed something simple.
Title: Re: How to reference a stencil's sub from a shape's user-defined Cell?
Post by: healthNut on August 10, 2012, 01:13:50 AM
I FIGURED IT OUT!! ;D

Had two subs:
testing()
tesing(shpObj as Visio.Shape)

Thought it works like C++ where both functions were valid, nope!
Title: Re: How to reference a stencil's sub from a shape's user-defined Cell?
Post by: Paul Herber on August 10, 2012, 01:20:57 AM
Nothing else (sensible) works like C++.
But, no, there is no function overloading in VBA.
Title: Re: How to reference a stencil's sub from a shape's user-defined Cell?
Post by: Jumpy on August 10, 2012, 06:27:04 AM
Quote from: healthNut on August 08, 2012, 01:11:15 PM
Thanks for those suggestions. Appreciate your honesty too, I thought I missed something simple.

See, you didn't miss something simple, you missed something complex (too complex for VBA)  :D
Title: Re: How to reference a stencil's sub from a shape's user-defined Cell?
Post by: healthNut on August 11, 2012, 01:40:20 AM
Thanks everybody. I am very grateful for your help.
Great community Vis guy built here.
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: 71 (show)
Files included: 25 - 925KB. (show)
Memory used: 773KB.
Tokens: post-login.
Cache hits: 7: 0.00110s for 22,302 bytes (show)
Cache misses: 1: (show)
Queries used: 9.

[Show Queries]