Getting Excel Object handles & Class names
Can Do
Goto Guest book sign in page [Home]
Thanks for visiting my site lucky visitor:
This page was last updated on: March 21, 2009
Copyright © 2002. XcelFiles. All Rights Reserved Ivan F Moala
Tell a friend about this page
Google
Search WWW Search My Site!

The following code was used to get the handles of the Excel objects and there Class names.
This was used to get the Namebox dropdown listbox handle and class name for the
Change Namebox width routine here:

If you read Whats up Classes & things, you would realise that all Excel objects have their Windows handle and Class names. Getting these two properties allows us to manipulate some of the objects properties eg. Namebox width. Of course you could have used an external application to get these, but it was good practice to be able to do this within Excel.

In order to do this we need to use some API's

What we basically need to do is to some how get a window handle via some type of user input.
This can be accomlished via the mouse position, which is tracked by your windows operating system and the API functions;

GetCursorPos
WindowFromPoint

How do I know that these are tracked by your Windows system?

Well, Windows is event driven, whilst there may appear to be nothing happening, in the background there are many messages that are queued (FIFO = First In First Out), sent and actioned to the appropriate applications main window. Windows waits for some user input, weather that is a keyboard, mouse or application input and sends messages to the appropriate interface. When you hide a window and then unhide it, for example, Windows sends that application a WM_PAINT message. The WM_PAINT message instructs the application to redraw its main window. Likewise, Windows sends the application a WM_MOUSEMOVE message every time the mouse moves over the application. This is important for our program as it is from this that we need to get the Window under the cursor. A great way to view these messages is Via Spy++

There are 3 basic messages,
Action - instructing a Window to perform some action.
Event  - a notification message that tells a Window that some event has happended.
User Defined - a msg a program may send ie a programer may use API SendMessage().

These messages can be either;
A Queued Message: eg Key Board Activities, WM_MOUSEMOVE – any mouse movement
WM_KEYDOWN, WM_KEYUP, WM_CHAR – characters from key strokes, WM_TIMER – timer message, WM_PAINT – repaint message etc OR

A Nonqueued Message: eg. calling certain Windows functions Explicitly sending message by calling SendMessage(), WM_CREATE, WM_SIZE etc.

Have a look below @ the screen shot of the Userform and resulting output. You will note that I also used it to get Windows from out side of the Excel application eg. Start button, Clock.

(I'm always looking to improve this, so if you have any suggestions then please contact me)
Userform used to get the Windows handles & Class names
Displayed Output from above Userform > Clicking [Copy to Sheet]
Downloads (08 March 2003)
Downloads (26 March 2004)
Here is the amended workbook, if you have the old version I suggest you download this version.
Amendments:
1) Keep form OnTop
2) Keep scroll visible

With these 2 amendments you can view more easily what is running.
Many of the individuals who created these codes have a programming degree, but you don't need one to use them. You can get a quick online education just by doing a little research on coding. Think a career in computer coding could be for you? You can always take a career assessment test to find out!