Disable/Enable button in Excel/VBA


I'm trying the following function in VBA/Excel:

Sub function_name()
  Call Long_Function       ' duration: 10sec
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!

This question is tagged with vba excel

~ Asked on 2013-01-02 13:31:16

The Best Answer is


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.

~ Answered on 2013-01-02 15:01:41


... I don't know if you're using an activex button or not, but when I insert an activex button into sheet1 in Excel called CommandButton1, the following code works fine:

Sub test()

   Sheets(1).CommandButton1.Enabled = False

End Sub

Hope this helps...

~ Answered on 2013-01-02 13:37:01

Most Viewed Questions: