Remove Dynamically Added Controls from Userform

前端 未结 6 562
野的像风
野的像风 2021-01-02 01:13

I have an Excel userform with dynamically added checkboxes.

I add the checkboxes with code that looks like this:

Set chkBox = Me.Controls.Add(\"Forms         


        
6条回答
  •  慢半拍i
    慢半拍i (楼主)
    2021-01-02 02:04

    I rewrote the original code using command buttons, and just added "Me.Controls.Count" rather than "NumControls" and defined "Cont" as a Control. It seems to be working for me. Please let me know if this works for you:

    -->

    On Error Resume Next
    Dim Cont As Control
    Dim C As Integer
    'Remove all dynamically updated checkboxes
    For Each Cont In Me.Controls
        For C = 1 To Me.Controls.Count
        If Cont.Name = "CommandButton" & C Then
            Me.Controls.Remove ("CommandButton" & C)
        End If
        Next C
    Next Cont
    

提交回复
热议问题