gpt4 book ai didi

excel - 通用事件处理程序,用于获取在 VBA 中单击的 ActiveX 按钮的名称。

转载 作者:行者123 更新时间:2023-12-04 21:25:01 25 4
gpt4 key购买 nike

所以我想知道我是否可以引用被点击的按钮。所以我不必为每个按钮更改太多代码。所以这就是我所拥有的。

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

而不是 With CommandButton1我希望它使用被点击的按钮。我试过 With Me但它什么也没做。

最佳答案

The answer in this SO post解决您的问题。

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

编辑:

实际上,这很容易。

屏幕截图:

我的工作表设置:

enter image description here

VBE 的设置,Sheet1 的代码:

enter image description here

注意突出显示的部分!

VBE 的设置,类模块:

通过插入 Class Module 添加一个类模块而不仅仅是Module .名称应该是 ButtonEvents .

enter image description here

单击 CommandButton1 时的结果:

enter image description here

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

当然,这只是基本前提。您可以更改类模块中的代码以将名称存储在某处或将其发送到特定单元格等,而不是显示消息框。

希望这能让它更清楚。

关于excel - 通用事件处理程序,用于获取在 VBA 中单击的 ActiveX 按钮的名称。,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21010716/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com