通用事件处理程序,用于获取在VBA中单击的ActiveX按钮的名称. [英] Common event handler to get the name of ActiveX button clicked in VBA.

查看:37
本文介绍了通用事件处理程序,用于获取在VBA中单击的ActiveX按钮的名称.的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以我想知道我是否可以引用单击的按钮.因此,我不必为每个按钮将代码更改太多.所以这就是我所拥有的.

So I was wondering if I can reference the button that was clicked. So I do not have to change the code to much for every button. So here is what I have.

Private Sub CommandButton1_Click()

Dim name As String
With CommandButton1

If .Caption = "CommandButton1" & "" Then
name = InputBox("Enter Template Name.")
.Caption = name

End If
End With

End Sub

我希望它使用单击的按钮,而不是使用CommandButton1的.我尝试了 With Me ,但没有执行任何操作.

Instead of With CommandButton1 I want it to use the button that was clicked. I tried With Me but it did nothing.

推荐答案

请仔细按照说明进行操作.它应该可以解决您的问题.:)

Follow the instructions carefully. It should solve your problem. :)

实际上很简单.

屏幕截图:

我的工作表的设置:

VBE的设置,Sheet1的代码:

注意突出显示的部分!

NOTE THE HIGHLIGHTED PARTS!

VBE的设置,班级模块:

通过插入 Class Module 而不只是 Module 添加类模块.名称应该完全是 ButtonEvents .

Add a class module by inserting Class Module rather than just Module. The name should exactly be ButtonEvents.

单击CommandButton1时的结果:

==============

当然,这只是基本前提.除了显示消息框外,您还可以在类模块中更改代码,以将名称存储在某个位置或将其发送到特定的单元格,等等.

This is just the basic premise, of course. Instead of showing a message box, you can instead change the code in the class module to have the name stored somewhere or send it to a particular cell, etc.

希望这更加清楚.

这篇关于通用事件处理程序,用于获取在VBA中单击的ActiveX按钮的名称.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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