RUNMACRO from stencil to document

Started by jimm_i, September 03, 2009, 05:54:45 AM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

jimm_i

Hi guys,

I've written a macro that grabs some information about what shapes a connector is connected to ( http://visguy.com/vgforum/index.php?topic=1156.0 ) and its working perfectly from within my document.
What I want to do is move this code out into a stencil that i've created so I don't have to add the code into every document that I create.

At the moment i've set the formula in my connectors shapesheet EventXFMod cell to =RUNMACRO("Module1.Connections") so that its referencing the code within the document & will run the macro whenever I move the connector or change the shape that its connected to.

I've been trying to change this reference to the document vba module to a reference to my stencil vba module, without having a lot of luck.
The only thing i've had any success with at all is =RUNMACRO("TheDocument.Connections","Audio Stencil") where I can successfully drag my master onto a document without visio throwing up errors. Unfortunately, the macro isn't running when I do this, so none of my information fills out.

Is it possible to reference a macro outside of a document, or am I better off just creating a template that contains the vba code & using that every time I create a new document?

Cheers

JuneTheSecond

#1
Hi,

I think it is easy to move macro from drawing to stencil.
Only 2 notes on this work are to use project name of the stencil for second argument in RunMacro function,
and to use "ActiveDocument", if "ThisDocument" is used. ThisDocument means the stencil itself.

Visio has other functions to run macro, such as CallThis, RunAddon, etc..
I think RunMacro is the best, because your RunMacro on the drawing works fine, though I often use CallThis function.
Best Regards,

Junichi Yoda
http://june.minibird.jp/

jimm_i

Thanks for the reply.

I've got it all working now. I didn't realise that I had to add my stencil to my list of references for the new drawing, once I added the reference my formula worked perfectly.

One note on that though, initially I had my stencil saved on a network drive & when I tried to add it to my list of references, visio came up with an unspecified automation error & it wouldnt work. When I moved the stencil onto my local drive, it worked fine.

It would be nice to be able to place the stencil on my network so that a couple of other guys have access to it, but I think i'll just leave the network drive version as a main that we can copy over to our local drives before using.