BB code in posts seems to be working again!
I haven't turned on every single tag, so please let me know if there are any that are used/needed but not activated.

Main Menu

Custom Shape EventDrop Macro only work on Stencil?

Started by hakayeazure, July 09, 2008, 09:40:55 AM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.



I have a problem creating custom shape using visio, could someone help me please.

I've develop a simple custom shape for testing:
1. I open a new stencil
2. and I add a new master named MyShape then I edit it
3. I put a rectangle shape, select it, and execute Window - Show ShapeSheet
4. On Events section, EventDrop cell, i enter =RUNMACRO("ThisDocument.ShowOption")
5. Using VB Edtior, Under ThisDocument module, I created a public subroutine named ShowOption which show a hello world message box

When I tried to create a new instance of MyShape in stencil page, a message box showing Hello World text appear, but, the problem is when I tried to create a new instance of MyShape into drawing page, nothing happen.

I've tried other ways, like changing EventDrop value into:
combination of +SETF("EventDrop",0)
place the subroutine into a module.

None working!

If possible, I'd like to create a custom shape which its shape can be determine using an option form which appear on instantiation, such as an option asking how many side the shape has, enter 3 - wooop a triangle, enter 4 - wooop a rectangle etc.



Wow, thats was quick answer, thanks Lars-Erik.

Mmm... how can I use your Smart Shape other than inside Test.vsd?

Maybe I can save it as a template document... But how can I use it over an existing document? or how can I use it like any other shapes? (like Basic Shapes in Block Diagram which can be inserted into any drawing page, or how to copy Smart Shape into My Shapes --> Favorites)

Thanks a lot.


The easiest way to copy the shape to one of your own documents would be to drop it on a page, copy it, and then paste it into you own document. Then you can just drag it into a stencil or do with it like anything else.
Ofcourse it will require the macro in the document i attached to be copied aswell.

If you want to make one of your own shapes do this you should do the following:
1-Create a macro in the "ThisDocument" section

Public sub Dropped()
msgbox("Hello World")
End sub

2- Open your shape's shape sheet.
3- find the OnDrop event
4- Make it: =RUNMACRO("ThisDocument.Dropped")
5- Drop the shape to a page and watch it run the macro

That should do the trick.

- Lars


Thanks again for the explanation...

I'd like to create a custom shape when I drop it onto the drawing page a form appear asking how many field there would be, lets say I put number 5 in it, then my custom shape will show 1 rectangle to type in the table name and 5 rectangles to type in fields name.

I think it would be a handfull if I'm asking for the macro so that custom shape below fully working  ;D unless it already developed!

So, maybe just let me know if it is possible to develop or not...

and again thanks for your help, I really appreciate it.  ;)

NB. My purpose is to create a database relationship diagram like we use to using Microsoft Access Database, kind of neat  ;D



Very much possible :)
Its a  nice project, and I have some time, I'll help you get started ;)


Well this is a start:
It will give the user a form and it will draw the require shapes.

Some things you might still improve/look at:
- Some better catching of errors / invalid input (very basic atm)
- Group the shapes when they have been dropped
- Could rewrite some code so you drop the master "Title" and the RUNMACRO would call it, the other shapes would be automaticly dropped on the right location below it and grouped (that would be really nice)
- Change the masters so the shapes end up looking better ;)
- Have some basic text added to the shape on dropping, you could use the loop counter for that ( "Field"&N )

I don't know how well you know VBA, if you need help with certain parts dont hesitate to ask, and keep us in the loop how it works out.

- Lars



I'm working on it...

And I promise I'll keep visguy posted  ;D


Visio Guy

Hi Guys,

I haven't checked the examples in detail, but one tip might come in handy...

For shapes like these, where you have a sub-shape "unit" that needs to be repeated, I try to put all intelligence regarding size and position into User-cells, and have these attributes key off of User.index.

The ultimate goal is to have the code simply duplicate a sub-shape, and increment User.index.

A simple example would be:

User.Index = 2

Height = GUARD( Sheet.5!Height - Height*User.Index )

Sometimes the Height formula gets blasted by the duplicate, so it helps to create user cells for those too. For example, make a User.height, then have the code automatically set Height = GUARD(User.Height). This simplifies your code, and the intricacies of what your code must do.

For articles, tips and free content, see the Visio Guy Website at
Get my Visio Book! Using Microsoft Visio 2010


Hi guys, thanks for all your help  ;)

I finally finish my first visio custom shape ;D thanks to Lars-Erik and Visio Guy.

Please check it up guys and I love to know if there is another way to do it...

When I finish this, I haven't read Visio Guy posting, kind of confuse on how to implement it either since I'm a 2 day visio newbie  ;D lot of visio terms that I dont know.

Thanks again guys! You have a great site here! Love it!



Very nice! One more thing I'd like to say about it though :)

Maybe consider integrating a nice way to fill in the subshapes.
Perhaps add a custom property for each field added and link the fields so the custom property ends up in the field?
I don't know what a nice way of filling in the fields is... Atleast if you have Visio pro the custom property way you can link Excel to it.

- Lars


No need to say it ;D I also feel that filling fields content is very inconvenient when I started to use it myself ;D

Also when actual field count changed, I need to redo the whole filling fields names process :'(

I'll posting it again after it been modified.



Heres some stuff I found:

- Dropping the shape, and pressing cancel will result in the shape being droped, and protected against deletion (Doh!)
- See if you can make it work with Visio 2007's theme function?

- Nice catching of the input value, 1000 is alot, but still only takes like 7 seconds. (depends on computer i suppose)
- 3,4 is a valid input, it rounds it off to 3 though. (just wondering if theres an easy way to catch this, can you check for integer? or just for numbers?)


Thanks for the debugging and the suggestions ;D I appreciate it...

And here is the improved result  ;D


Browser ID: smf (possibly_robot)
Templates: 4: index (default), Display (default), GenericControls (default), GenericControls (default).
Sub templates: 6: init, html_above, body_above, main, body_below, html_below.
Language files: 4: index+Modifications.english (default), Post.english (default), Editor.english (default), Drafts.english (default).
Style sheets: 4: index.css, attachments.css, jquery.sceditor.css, responsive.css.
Hooks called: 459 (show)
Files included: 34 - 1306KB. (show)
Memory used: 1242KB.
Tokens: post-login.
Cache hits: 13: 0.00193s for 26,766 bytes (show)
Cache misses: 2: (show)
Queries used: 15.

[Show Queries]