How to reference a stencil's sub from a shape's user-defined Cell?

Started by healthNut, August 07, 2012, 04:07:46 AM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

healthNut

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

Jumpy

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

healthNut

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")

Jumpy

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?

healthNut

Sure, thanks for asking.
The ThisDocument.testing and Testing.testing works
None of the stencil calls work

Jumpy

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)

healthNut

Thanks for those suggestions. Appreciate your honesty too, I thought I missed something simple.

healthNut

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!

Paul Herber

Nothing else (sensible) works like C++.
But, no, there is no function overloading in VBA.
Electronic and Electrical engineering, business and software stencils for Visio -

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

Jumpy

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

healthNut

Thanks everybody. I am very grateful for your help.
Great community Vis guy built here.