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
 

Some videos you may like

Excel Facts

Back into an answer in Excel
Use Data, What-If Analysis, Goal Seek to find the correct input cell value to reach a desired result

tlowry

Well-known Member
Joined
Nov 3, 2011
Messages
1,367
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
‘=============================================
 

Smitty

Legend
Joined
May 15, 2003
Messages
29,536
Welcome to the Board!

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

Me.Button25.Enabled = False

HTH,
 

Watch MrExcel Video

Forum statistics

Threads
1,122,576
Messages
5,596,981
Members
414,115
Latest member
SFUser

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
Top