Get Excel sheet object under the mouse
Is there any way to get the obj开发者_运维百科ect under the mouse in Excel sheet (not in the form).
The reason is that I have bunch of charts and some shapes on them. When I click the shape on the specific chart, macro is launched, doing some stuff to the current chart (ActiveChart). However, this works only if chart is activated prior to clicking shape on it. If you click shape without activating the chart, ActiveChart is Nothing.
So, I need some way to get the object/chart/cell which is under the mouse.
Sheet and Book don't have click or mousemove event. Setting the one on all charts I have also have the same problem as described.
I didn't also figure out how to find out which shape was clicked (since _Click macro doesn't have any parameters). E
Thanks.
You might try making all of your shape names unique, and include the chart name in each.
Then you can use Application.Caller within the macro handling the click to get the shape name. From that, you can parse out the chart name.
Tim
Clicking a chart WILL activate its parent sheet and book. So you could use something like
ActiveSheet.Charts(0)
if you only have 1 chart per sheet.
To find out what was clicked, you could have the caller provide its name/id either as an argument (might not be usable here) or by setting a global variable (not too nice but usable in a single user/single process context).
精彩评论