Finding Button Name

Jimmy P

New Member
Joined
Aug 23, 2014
Messages
45
I have part of a sub that captures a Button click, and then runs a processes. I want to disable the Button if the count in a cell = 0 (see red line in code) and enable it again when the sub is evoked again.

Here's what I have:

b???Enabled = True 'This is here to enable the Button when the sub is entered again after Cnt1 <> 0 and a new run starts.
Dim b1 As Button
Set b1 = ActiveSheet.Buttons("???")
If Cnt1 = 0 Then
MsgBox "There are no more Samples to Process" _
& vbCr & vbCr & "Click OK to make another selection or Quit the program", _
vbOKOnly + vbInformation, "Sample Run Over"
b???.Enabled = False
End If

The ??? is there because I can't find the Button properties name to use it (The Button text is "Load Sample & Start Processing)". I've tried turning on Design Mode through the Developer tab and then right clicked on the Button and the worksheet properties window opens in the VBA code window with no Buton properties shown. And there is no Properties selection for the Button showing when I right click on the Button.

Where are the Button properties located and will the code work if I do find the Button name and use it in place of ???.
 

Excel Facts

Quick Sum
Select a range of cells. The total appears in bottom right of Excel screen. Right-click total to add Max, Min, Count, Average.
If you used form buttons, then you must cycle the shapes to find them.
Code:
Dim shp As Shape
For Each shp In ActiveSheet.Shapes
  MsgBox shp.Name
Next

but if you used activeX buttons, then yes, it is in the controls.

Code:
For Each ctl In me.controls  
    MsgBox ctl.Name
Next
 
Upvote 0
instructions should be valid for Excel 2007 and later.

On the Developer tab make sure the Design Mode button is selected.
Click on the button in question and see what the text is in the "Name Box". This is the text area to the left of the formula bar and immediately above the column A header.
You can also change the buttons name by editting the name in this box as well.

Lastly, I don't believe you can actually 'disable' a non-ActiveX button so I recommend you change the button to an ActiveX button (the second set of controls on the INSERT section of the Developer tab.

You can then name the control whatever you want (e.g. "myButton") and call it as
Code:
ActiveSheet.myButton.Enabled = TRUE/FALSE
 
Last edited:
Upvote 0

Forum statistics

Threads
1,214,940
Messages
6,122,361
Members
449,080
Latest member
Armadillos

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