Disable button using function?

Currently using vba with excel 2007 ...

I am currently testing features and am a bit stuck with the buttons. I have two buttons called ONE and TWO. Pressing a button calls the Calc function with each button passing a variable to a different name. As below:

Private Sub ONE_Click() Calc TWO End Sub Private Sub TWO_Click() Calc ONE End Sub Function Calc(B As CommandButton) B.Enabled = False End Function 

I understand that pressing the ONE button passes the TWO variable to the Calc function, and then disables the TWO button.

I also have a button labeled Reset, which works as follows:

 Private Sub Reset_Click() ONE.Enabled = True TWO.Enabled = True End Sub 

As a result of this, if I press the ONE button, the TWO button will turn gray and “disabled” will appear. However, when I press the Reset button, it remains gray. Studying the properties of the button shows that it does not actually turn off. I installed another button that directly disables button two, i.e. TWO.Enabled = False, instead of using a variable for this.

When a button is directly disabled using the direct button, a reset allows the button to do as it should, and the properties reflect that the button is disabled.

Does anyone know why using a variable to disable such a button disables illusions? And even better, how to solve the problem?

+6
source share
1 answer

If you are having trouble calling an OTC link, use the static parameter.

 Private Sub ONE_Click() Calc "TWO" End Sub Private Sub TWO_Click() Calc "ONE" End Sub 

Now you can use this parameter to work with the object.

 Function Calc(B As String) If B = "ONE" Then ONE.Enabled = False ElseIf B = "TWO" Then TWO.Enabled = False Else Exit Function End If End Function 
+1
source

All Articles