Visio Guy

Visio Discussions => ShapeSheet & Smart Shapes => Topic started by: Visisthebest on October 04, 2021, 09:05:19 AM

Title: Triggering code in stencil only the first time, when shape is dropped
Post by: Visisthebest on October 04, 2021, 09:05:19 AM
I am still very much a shapesheet newbie but loving the DEPENDSON() function a lot!

Now also using it to get VBA code (in the stencil) to run the first time a shape is dropped on the page.

I added a user cell with this:
=CALLTHIS("ThisDocument.DT","DTStencil")+DEPENDSON(PinX)

Works like a charm, and I can of course add another user field where I set a flag when the code is run the first time (on drop on the page, when PinX is set for the first time), so the code checks the flag before running the full initializing code again when it is moved (I am using DEPENDSON on PinX after all).

No doubt there is also a way to do this on the shapesheet, so that after the first drop a shapesheet function sets a flag then the next time, when the shape is moved, CALLTHIS is not run again.

This is however beyond my knowledge of making more complex shapesheet formulas properly so any ideas how to do this much appreciated!

Title: Re: Triggering code in stencil only the first time, when shape is dropped
Post by: Surrogate on October 04, 2021, 09:46:06 AM
IMHO best way use EventDrop cell (https://docs.microsoft.com/en-us/office/client-developer/visio/eventdrop-cell-events-section) for single trigger
(https://i.imgur.com/uTWVxEu.png)
Something like this


EventDropCALLTHIS("ThisDocument.DT","DTStencil")
Title: Re: Triggering code in stencil only the first time, when shape is dropped
Post by: Visisthebest on October 04, 2021, 10:12:41 AM
Yes I should've used that one thank you Surrogate, didn't know about this possibility!