简体   繁体   English

如何在每个 ActiveX 复选框中使用相同的代码?

[英]How to use the same code in every ActiveX checkbox?

I want ActiveX checkboxes for filling rows and columns of a sheet.我想要 ActiveX 复选框来填充工作表的行和列。
I created a macro for the first checkbox.我为第一个复选框创建了一个宏。
I want to fill the rest of the sheet with checkboxes that process the same code as the first one.我想用处理与第一个代码相同的代码的复选框填充工作表的 rest。

Below is my example.下面是我的例子。

在此处输入图像描述

Working code of the ActiveX checkbox that works in cell B2在单元格B2中工作的 ActiveX 复选框的工作代码

Private Sub CheckBox1_Click()    
    If CheckBox1.Value = True Then    
        Shell "cmd.exe /c E:" & "gam update group " & (Cells(1, ActiveCell.Column)) & " add member " & Range("A" & (ActiveCell.Row))    
    ElseIf CheckBox1.Value = False Then    
        Shell "cmd.exe /c E:" & "gam update group " & (Cells(1, ActiveCell.Column)) & " delete user " & Range("A" & (ActiveCell.Row))
    End If    
End Sub

How can all the other checkboxes run the same code without having to copy/paste it into each checkbox?所有其他复选框如何运行相同的代码而无需将其复制/粘贴到每个复选框中?

Keep in mind, I am going to have hundreds of checkboxes on this sheet doing the same thing.请记住,我将在这张表上放置数百个复选框来做同样的事情。

You can try worksheetchange event and loop for each checkbox...您可以为每个复选框尝试工作表更改事件和循环...

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM