Re: handles in VBA

From: Stephen Bullen (stephen_at_oaltd.co.uk)
Date: 02/18/05


Date: Fri, 18 Feb 2005 08:46:10 GMT

Hi Karl,

> > so my questions: what does EnumChildWindows do exactly? what are the
> > "controls" of a form? (I belived they were windows) Is there a
> > difference between controls in VB and those ones in VBA?
> > How can I retrieve controls handles in VBA with simple API calls?
> ================================================================
> ================================================================
> ================================================================
>
> Seems to me the answer to that should pretty well be the same regardless of what
> application is hosting VBA, right?

Absolutely - most of the controls on Userforms are either window-less (lightweight) or
totally owner-drawn. Either way, they don't have hWnds, so we can't manipulate them
using API calls. The few controls that do have a window (e.g. Edit Boxes) seem to be
very specific implementations (rather then using the standard Windows controls), that
only respond to a very limited set of messages. Of course, adding other controls from
outside the MSForms library (e.g. TreeView, ListView etc) works just as well in VBA as
in VB. They either have their own hWnd property which we can read and use, or it can
be found using FindWindowEx.

> Interesting! I guess I wasn't aware that even the forms package(s) can and do vary!
> So that really could be a unique wrinkle to his original query. Patrick is using a
> licensed copy of VBA, hosted by MicroStation (a CADD package).

Access is the only special case I know of, because it's had a forms package since its
inception. I guess it didn't make sense to support both Access forms and userforms
together.

Regards

Stephen Bullen
Microsoft MVP - Excel
www.oaltd.co.uk