View Single Post
  #5   Report Post  
Posted to microsoft.public.excel.programming
Jon Peltier Jon Peltier is offline
external usenet poster
 
Posts: 6,582
Default Number of UserForm Control Objects

Another supposedly legal thing you can do in VB is something that does
not make any sense upon closer examination -- but MS made it work anyway.
It's the "Unload Me" statement (or possibly some similar statements).
"Me"
is the default for the control or form whose code you are working with.
Bugs
related to this type of problem cannot be debugged without high level
support
from MS. (Right, it cost me a bundle when it happened to me!) In my
case,
Excel itself went "poof!"

I would never use the "Me" reference. One thing is this: what will
happen if the code is cut and pasted and you forget it used the Me thing?
It
will attempt to change properties and invoke methods where Me now refers
to
something else.


I'm not sure what you're saying here, or what doesn't make sense. Me is the
keyword for the module containing the code. Me.Hide hides the userform
containing that line of code. Unload Me unloads the userform, which isn't
the most efficient way to unload a form (i.e., from the form's own code),
but it nominally works.

Whenever you cut and paste code, you have to take care with references. 'Me'
is no worse than 'ActiveSheet' or 'Workbooks("Fred.xls")'.

My last clue is the hope you are not dynamically creating controls on
the
fly -- especially, making control arrays. This can really be tricky.
Make
sure you do not have any control arrays that really do not need to be
arrays.


It sure is tricky to make control arrays in VBA, especially since VBA does
not support control arrays.

I would suggest studying a decent VBA resource.

- Jon
-------
Jon Peltier, Microsoft Excel MVP
Tutorials and Custom Solutions
Peltier Technical Services, Inc. - http://PeltierTech.com
_______