Visio Guy

Visio Discussions => Programming & Code => Topic started by: jrinn on November 09, 2010, 01:01:59 AM

Title: still can't access subroutines in stencil from shapesheet action
Post by: jrinn on November 09, 2010, 01:01:59 AM
I've read a bunch of the posts in this forum and it looks to be a piece of cake to point to a macro in a stencil and call it out via a shapesheet action or event.  I had a simplified version working when all were in the same file, but now I'm trying to do what it looks like can be done and I'm getting stiffled.

I created some shapes with a double click event calling out macros different ways.  I had to resort to adding the macros locally and renaming them just to see if I was doing something really stupid.  I'm still having major problems.  I've tried using dozens of variations of RUNMACRO, CALLTHIS, RUNADDON, RUNADDONWARGS,...

Can someone please check out this simple code and tell me what I'm doing wrong?

Thanks,
   JPR

Title: Re: still can't access subroutines in stencil from shapesheet action
Post by: Nikolay on November 09, 2010, 04:57:02 AM
I think you can't call a macro in a stencil from shape sheet directly.
Why did you think you could do that?
Title: Re: still can't access subroutines in stencil from shapesheet action
Post by: Jumpy on November 09, 2010, 09:05:11 AM
You can only do it with Callthis. First arg is the procedure name in "quotation marks", followed by the project name. The project name is the stencil name.

http://msdn.microsoft.com/en-us/library/ms406651%28office.12%29.aspx
Title: Re: still can't access subroutines in stencil from shapesheet action
Post by: Nikolay on November 09, 2010, 11:20:31 AM
Ups. I was wrong. It is perfectly possible. Sorry ::)
Just change your functions in the stencil so that they accept SHAPE (!!!) as first argument, and then all other arguments. Like this:


CALLTHIS("ThisDocument.MacroArgumentPassingNone","macros")

CALLTHIS("ThisDocument.macroArgumentPassingString","macros","SomeString")



Public Sub MacroArgumentPassingNone(s As Shape)
    MsgBox ("nothing was passed")
End Sub

Public Sub macroArgumentPassingString(s As Shape, ByVal PassString As String)
    MsgBox ("a single string was passed = " & PassString)
End Sub
Title: Re: still can't access subroutines in stencil from shapesheet action
Post by: jrinn on November 09, 2010, 03:12:12 PM
Worked great!  Thank you both.

Yeah I was following all of the online help with no luck, but the key was to also declare the shape as a variable when using CALLTHIS.  This was counter-intuitive to me since I was trying to match up and have the same number of arguments (as most other code requires). Is that also necessary if you use RUNMACRO, RUNADDON or RUNADDONWARGS?

From now on I'm not going to waste a whole day before sacrificing my pride and asking for help.
Thanks again.
    JPR
Title: Re: still can't access subroutines in stencil from shapesheet action
Post by: Nikolay on November 09, 2010, 04:35:10 PM
Don't sweat it  ;)
Frankly speaking, I thought that it is was not possible as well.
Title: Re: still can't access subroutines in stencil from shapesheet action
Post by: Jumpy on November 09, 2010, 08:07:46 PM
Only Callthis passes along as (default) first argument a reference to the calling shape.

The others (RUNMACRO, RUNADDON or RUNADDONWARGS) don't do this.

I just read that RUNMACRO could work, too, because you can pass along the project as second arg, too. Didn't knew that, because I always thought, that you need a reference to the project with RUNMACRO, but the following link proved me wrong:

http://msdn.microsoft.com/en-us/library/ms425549(v=office.12).aspx



But RUNADDON or RUNADDONWARGS  definitley can't call to code in the stencil without a reference.

Jumpy
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: 59 (show)
Files included: 25 - 925KB. (show)
Memory used: 762KB.
Tokens: post-login.
Cache hits: 7: 0.00116s for 22,302 bytes (show)
Cache misses: 1: (show)
Queries used: 9.

[Show Queries]