获取鼠标下的Excel工作表对象

发布于 2024-09-30 11:08:26 字数 319 浏览 1 评论 0原文

有没有办法在Excel工作表(而不是表单)中获取鼠标下的对象。

原因是我有一堆图表和上面的一些形状。当我单击特定图表上的形状时,宏将启动,对当前图表(ActiveChart)执行一些操作。但是,只有在单击图表上的形状之前激活图表时,此功能才有效。如果单击形状而不激活图表,ActiveChart 就什么也不是。

所以,我需要某种方法来获取鼠标下方的对象/图表/单元格。

工作表和书籍没有单击或鼠标移动事件。在所有图表上设置一个我也遇到了与所描述的相同的问题。

我也没有弄清楚如何找出单击了哪个形状(因为 _Click 宏没有任何参数)。谢谢

Is there any way to get the object 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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

仲春光 2024-10-07 11:08:26

您可以尝试使所有形状名称都唯一,并在每个形状中包含图表名称。

然后,您可以在处理单击的宏中使用 Application.Caller 来获取形状名称。由此,您可以解析出图表名称。

蒂姆

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

所有深爱都是秘密 2024-10-07 11:08:26

单击图表将激活其父表和书籍。所以你可以使用类似的东西
ActiveSheet.Charts(0)
如果每张纸只有一张图表。
要找出单击的内容,您可以让调用者提供其名称/ID 作为参数(此处可能无法使用)或通过设置全局变量(不太好,但可在单个用户/单个进程上下文中使用)。

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).

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文