disable button using vba

Miniv

New Member
Joined
Nov 10, 2011
Messages
6
Hello,

I need to disable the command button by name button 25,on the worksheet.So can you plz tell me how to do that disable,its not based on any condition i am doing this in other macro.So i need to just disable it.

Plz help me,

Thanks
 

Excel Facts

Why does 9 mean SUM in SUBTOTAL?
It is because Sum is the 9th alphabetically in Average, Count, CountA, Max, Min, Product, StDev.S, StDev.P, Sum, VAR.S, VAR.P.
A button is not a snap

I think this may be over kill, but here it is. I suggest you try it on a practice app at first to see if you will use this.

<table style="border-collapse:collapse; mso-padding-alt:0in 5.4pt 0in 5.4pt" border="0" cellpadding="0" cellspacing="0"> <tbody><tr> <td style="width:1.7in;padding:0in 5.4pt 0in 5.4pt" valign="top" width="204"> Sub
</td> <td style="width:202.5pt;padding:0in 5.4pt 0in 5.4pt" valign="top" width="338"> Purpose

</td> </tr> <tr> <td style="width:1.7in;padding:0in 5.4pt 0in 5.4pt" valign="top" width="204"> Sub enable25()
</td> <td style="width:202.5pt;padding:0in 5.4pt 0in 5.4pt" valign="top" width="338"> Run to enable button
</td> </tr> <tr> <td style="width:1.7in;padding:0in 5.4pt 0in 5.4pt" valign="top" width="204"> Sub disable25()
</td> <td style="width:202.5pt;padding:0in 5.4pt 0in 5.4pt" valign="top" width="338"> Run to disable button
</td> </tr> <tr> <td style="width:1.7in;padding:0in 5.4pt 0in 5.4pt" valign="top" width="204"> Disable_Enable()
</td> <td style="width:202.5pt;padding:0in 5.4pt 0in 5.4pt" valign="top" width="338"> Does the work
</td> </tr> <tr> <td style="width:1.7in;padding:0in 5.4pt 0in 5.4pt" valign="top" width="204"> DoNothing()
</td> <td style="width:202.5pt;padding:0in 5.4pt 0in 5.4pt" valign="top" width="338"> Runs when disabled button is pressed
</td> </tr> <tr> <td style="width:1.7in;padding:0in 5.4pt 0in 5.4pt" valign="top" width="204"> DoSomething()
</td> <td style="width:202.5pt;padding:0in 5.4pt 0in 5.4pt" valign="top" width="338"> Runs when enabled button is pressed
</td> </tr> </tbody></table>
‘=============================================
Sub enable25()
Disable_Enable True, "Button 25"
End Sub
‘=============================================
Sub disable25()
Disable_Enable False, "Button 25"
End Sub
‘=============================================
Sub Disable_Enable(bEnable As Boolean, bname As String)
Select Case bEnable
Case False
With ActiveSheet.Shapes(bname)
.OnAction = "DoNothing"
.Select
End With
Selection.Characters.Font.ColorIndex = 15
Case Else
With ActiveSheet.Shapes(bname)
.OnAction = "DoSomething"
.Select
End With
Selection.Characters.Font.ColorIndex = xlAutomatic
End Select
SendKeys "{ESC}"
End Sub
‘=============================================
Sub DoNothing()
Exit Sub
End Sub
‘=============================================
Sub DoSomething()
MsgBox "Enabled"
End Sub
‘=============================================
 
Upvote 0
Welcome to the Board!

What kind of button is it? For an ActiveX control you can use:

Me.Button25.Enabled = False

HTH,
 
Upvote 0

Forum statistics

Threads
1,214,869
Messages
6,122,012
Members
449,060
Latest member
LinusJE

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top