如何为多个按钮分配通用步骤?

编程入门 行业动态 更新时间:2024-10-27 13:32:08
本文介绍了如何为多个按钮分配通用步骤?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

前段时间,我有一个示例代码为多个按钮分配相同的过程.像这样:

Some time ago I have a sample code to assign the same procedure for multiple buttons. Something like this:

For Eeach buttton in Form1 If button is clicked MsgBox button.Caption.

但是我现在找不到此代码.谷歌搜索,我找不到我所需要的东西.我只记得我需要插入一个类模块.有人可以给我一个链接或一个简短的例子.

But I can't find this code now. Googling I cant found egzactly what I need. I just remember that I need to insert a class module. Could someone give me a link or a short example.

推荐答案

插入一个新的类模块,并将其命名为 clListener (我才想到).其中的代码:

Insert a new Class Module and name it clListener (that just came to my mind). Code in there:

Public WithEvents ct As MSForms.CommandButton Public Sub ct_Click() MsgBox ct.Name & " clicked!" End Sub

在用户窗体模块中:

Private listenerCollection As New Collection Private Sub UserForm_Initialize() Dim ctItem Dim listener As clListener For Each ctItem In Me.Controls If TypeName(ctItem) = "CommandButton" Then Set listener = New clListener Set listener.ct = ctItem listenerCollection.Add listener End If Next End Sub

更多推荐

如何为多个按钮分配通用步骤?

本文发布于:2023-11-23 09:10:32,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1620888.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:多个   何为   按钮   步骤   分配

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!