none
How to delete a control from a userfom using vba codes RRS feed

  • Question

  • Private Sub CommandButton1_Click()
    Dim ctl As Control
    Set ctl = UserForm1.Frame1.Controls("CommandButton2")

    UserForm1.Frame1.Controls.Remove (ctl.Name)

    End Sub

    run-time "444"

    Method can't be used in this context

    How to delete a control from a userform?

    Friday, September 8, 2017 8:58 AM

All replies

  • Hello,

    We can only delete controls added at runtime. So please add the command button when initializing.

    Private Sub UserForm_Initialize()
    Me.Frame1.Controls.Add "Forms.CommandButton.1", "CommandButton2"
    End Sub

    Besides, this forum is for development issues when using Office JavaScript API. As your issue is about VBA. I would move this thread into VBA forum.

    Regards,

    Celeste


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Monday, September 11, 2017 2:26 AM
    Moderator