PDA

View Full Version : Solved: Userform events for dynamic controls



mvidas
06-13-2007, 11:33 AM
Hi All,

Not exactly an excel question, really applies to any office userform. This is just our busiest forum :)

I'm adding a bunch of controls at runtime to my userform, and I need access to their _click events. I know how to do this if I were to use a class module, and I will probably end up doing that, but I'm really hoping to keep all the code in the userform itself.

I know I could just put in a bunch of _click events in hopes that the number I add never goes above the pre-coded events, but I'm hoping for something better.
Since I can't use control arrays in VBA, does anyone know a tricky way of doing this? Though I don't know of it, I'm hoping there something like:controls("controlname").assignevent "click", "myclickevent"
And in reality, this is for outlook, which has no VBE access so I can't even go that route.

If you know for sure that there is no such thing, please post that too. I think chances are I'm just gonna have to deal with a class module for the time being (until I go the com add-in route).

mikerickson
06-13-2007, 12:39 PM
You can write direcly to the code module for the userform. This reference should help
http://www.ozgrid.com/forum/showthread.php?t=69411

mvidas
06-13-2007, 12:53 PM
Wish I could.. unfortunately outlook doesnt have programmatic VBE access (I should have been more explicit) so that is out.

I should just mark this solved, I decided to just go with the class module route and make the end users just import two files instead of one. Thanks though

Bob Phillips
06-13-2007, 01:03 PM
Matt,

Could you create/update the userform in some other app, and export it to Outlook?

mvidas
06-13-2007, 01:10 PM
I thought about that but can't bring it back into outlook at runtime (though I could just open it up in an instance of excel and show it there). Seems like its reaching though. I think once I make it into an add-in (back to one file) it will make things easier, and just deal with the separate class for now (I realized after I posted this that I probably shouldn't have :))

mvidas
06-13-2007, 01:39 PM
Bob (or Mike), if you want to take a look and see if I'm just missing something, feel free. Its a photo viewer for attached images in outlook, I'll attach it here