View Single Post
  #5   Report Post  
Posted to microsoft.public.excel.programming
Charlotte E Charlotte E is offline
external usenet poster
 
Posts: 59
Default Current Control Object ?

Thanks for your PoWs - I've saved this in my 'little' VBA library :-)


jamescox wrote:
Thought it might be that, but there was always a chance I was missing
some deeper advantage. However, don't get me wrong - I'm a big fan of
POLE (Path Of Least Effort). :Bgr

The next step that comes to mind - if your code for a group of the
userform controls is essentially identical - is to put that code in a
Private Sub and pass CCO as a parameter to the Sub. That way, you
only have one place to type the Sub code - and more importantly, only
one place to change / modify it. But, you may already be doing
that...

Two comments - you would gain a bit of speed if you would declare CCO
as the appropriate type of control instead of Object. It's not like
it was a mystery what type of control it is, because the Dim is in the
event code of a specific control.

If you use Object, VBA has to take a look at what the properties of
Me.ActiveControl are, figure out what kind of control it is and then
create an instance of that kind of control for your Set statement.
That doesn't take a whole lot of time, but if it has to be done often
enough, it adds up. Also, if you declare it as the proper type of
control, Intellisense (the feature of VBA that shows you allowable
methods and properties as you type) will work.

Finally, don't forget to use CCO = Nothing to clean up after you don't
need CCO any more.

(BTW, in terms of knowing 'who' called what code, don't forget the
Caller method for regular subs and functions.)