vba按钮 - 找到被点击 [英] vba button - find which was clicked

查看:644
本文介绍了vba按钮 - 找到被点击的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已将宏分配给几个按钮。



如何找到内部宏哪个按钮被点击?



我正在以用户形式进行操作,他可以​​在家中输入人物:



name1:

surname1:



name2:

surname2:
添加下一个成员|



我希望按钮始终显示在最后添加的人的最后一行。
为简单起见,我认为最好在
表中拥有100个空表单,但在开始时都不可见。

然后当用户点击添加下一个成员时,我只需下一个行可见,
和移动按钮到下一个人。但是要做到这一点,我需要知道我现在的位置。



与删除类似,当删除按钮被点击时,将使行隐藏。



name1:

surname1:
[remove]



name2:

surname2:
[remove]



name3:

surname3:
|添加下一个成员|



我需要知道哪个删除按钮被点击。 >

编辑:
在网络中找到 - 你觉得,似乎是最好的/方式

  Dim r As Range 
设置r = ActiveSheet.Buttons(Application.Caller).TopLeftCell
范围(Cells(r.Row,r.Column ),Cells(r.Row,r.Column))。选择


解决方案

我总是为每个按钮写封包,然后调用所讨论的宏。



像这样:

  Public Sub StoreButton_Click()

调用StoreTrans值(ActiveSheet)

End Sub

如果您只有一个按钮任何一个页面,您可以获取ActiveSheet属性,它将是该页面上的按钮。






编辑:



以下是获取和使用调用按钮名称的代码:

  Dim ButtonText As String 

ButtonText = Application.Caller

ActiveSheet.Shapes(ButtonText).Delete

您可以使用.Move方法移动按钮。


I have assigned macro to few buttons.

How can I find out inside macro which button was clicked?

I am doing as user form, where he can input peoples from family:

name1:
surname1:

name2:
surname2:
|add next member|

I wish button to appear always in last row of the last added person. For simplicity I think it is better to have like 100 empty forms in the sheet but all invisible at the begining.
Then when user clicks add next member I simply make next rows visible, and move button to next person. But to do that I need to know my current position.

Similar with deletion I would make rows invisible when remove button is clicked.

name1:
surname1:
[remove]

name2:
surname2:
[remove]

name3:
surname3:
|add next member|

I need to know which remove button was clicked.

EDIT: Found in web - what do you think, seems to be best /way

Dim r As Range
Set r = ActiveSheet.Buttons(Application.Caller).TopLeftCell
Range(Cells(r.Row, r.Column), Cells(r.Row, r.Column)).Select

解决方案

I always write wrappers for each button that then call the macro in question.

Like so:

Public Sub StoreButton_Click()

  Call StoreTransValues(ActiveSheet)

End Sub

If you have only one button for any one page, you can just get the ActiveSheet property, and it will be the button on that page.


Edit:

Here's the code to get and use the name of the calling button:

Dim ButtonText As String

ButtonText = Application.Caller

ActiveSheet.Shapes(ButtonText).Delete

You would use the .Move method to move the button.

这篇关于vba按钮 - 找到被点击的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆