+ Reply to Thread
Results 1 to 3 of 3

Disable ALL Buttons on Button Click in UserForm

Hybrid View

  1. #1
    Forum Contributor
    Join Date
    04-03-2012
    Location
    Washington State
    MS-Off Ver
    Excel 365
    Posts
    340

    Disable ALL Buttons on Button Click in UserForm

    Hello... I have about 20 buttons on a form and I wondered if there is an easy way to disable all other buttons once any ONE button is clicked.

    All I have for now is....

    If Me.CommandButton1.Enabled Then
    Me.CommandButton2.Disabled = True
    Me.CommandButton3.Disabled = True
    End If
    Etc Etc ... I just want to click one and all the rest disable.
    Thanks in advance!

  2. #2
    Forum Expert tigeravatar's Avatar
    Join Date
    03-25-2011
    Location
    Colorado, USA
    MS-Off Ver
    Excel 2003 - 2013
    Posts
    5,361

    Re: Disable ALL Buttons on Button Click in UserForm

    Nu2Java,

    Create a private function in the userform code module:
    Private Function DisableButtons(ByVal strEnable As String)
        
        Dim ctrl As Control
        
        For Each ctrl In Me.Controls
            If TypeName(ctrl) = "CommandButton" And ctrl.Name <> strEnable Then
                ctrl.Enabled = False
            End If
        Next ctrl
        
    End Function

    Then put this code in each of the command button click events:
    Private Sub CommandButton1_Click()
        
        DisableButtons Me.ActiveControl.Name
        
    End Sub
    
    Private Sub CommandButton2_Click()
        
        DisableButtons Me.ActiveControl.Name
        
    End Sub
    
    Private Sub CommandButton3_Click()
        
        DisableButtons Me.ActiveControl.Name
        
    End Sub
    Hope that helps,
    ~tigeravatar

    Forum Rules: How to use code tags, mark a thread solved, and keep yourself out of trouble

  3. #3
    Forum Contributor
    Join Date
    04-03-2012
    Location
    Washington State
    MS-Off Ver
    Excel 365
    Posts
    340

    Re: Disable ALL Buttons on Button Click in UserForm

    tigeravatar,

    Thanks very much for your time and help... Greatly appreciated!

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1