I'm trying the following function in VBA/Excel:
Sub function_name()
button.enabled=false
Call Long_Function ' duration: 10sec
button.enabled=true
End Sub
For some reason, this button disabling does not work (it stays enabled in the excel work sheet) I tried experimenting with DoEvents and delays, but no luck there. Any ideas? Thanks!
Right click the sheet that contain the button, and then choose View Code from the context menu, in the Microsoft Visual Basic for Applications window, please copy and paste the below code into the blank module, see screenshot: VBA code: Enable or disable a button based on two cell values: Private Sub Worksheet_Change( ...
The following works for me (Excel 2010)
Dim b1 As Button
Set b1 = ActiveSheet.Buttons("Button 1")
b1.Font.ColorIndex = 15
b1.Enabled = False
Application.Cursor = xlWait
Call aLongAction
b1.Enabled = True
b1.Font.ColorIndex = 1
Application.Cursor = xlDefault
Be aware that
.enabled = False
does not gray out a button.
The font color has to be set explicitely to get it grayed.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With