如何在 VBA 中识别单击的形状名称

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/19763629/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-08 17:05:39  来源:igfitidea点击:

How to identify the clicked shape name in VBA

excelvbaexcel-vba

提问by fyr91

I am trying to create an excel template where I have already assigned different macros to different shape that act as buttons. Now I am having problem of locating which one I have clicked since I need to modify the attributes of the clicked shape after clicking on that shape. While searching on this problem, I have noticed that there is a way to identify which shape has been selected whereas I still doesn't know How to get the name of the shape I have clicked or is there a way to refer to that clicked shape in VBA? Thank you!

我正在尝试创建一个 excel 模板,其中我已经将不同的宏分配给充当按钮的不同形状。现在我在定位我单击了哪个形状时遇到了问题,因为我需要在单击该形状后修改所单击形状的属性。在搜索此问题时,我注意到有一种方法可以识别已选择的形状,而我仍然不知道如何获取我单击的形状的名称,或者有没有办法引用该单击的形状在 VBA 中?谢谢!

回答by Sam

You should be able to get the name of the clicked shape by using Application.Caller

您应该能够通过使用获得点击形状的名称 Application.Caller

usage as shown

用法如图

 CallingShapeName = ActiveSheet.Shapes(Application.Caller).Name 

 msgbox CallingShapeName

回答by user12573120

ActiveSheet.Shapes(Application.Caller).TextFrame.Characters.Text