command buttons

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi, I have a large number of command buttons and I need to change the name on
them, they all have the same name, I know that I can change the name by using
edit but I was wondering if there is a quick way to do it with more than one
at a time, I have about 300 buttons in two rows down two columns.

Thanks in advance, Wildauk.
 
Name or caption. (I assume caption)
each has their own property window.

you can do it with code if there is some pattern to your madness

Dim oleObj as Object
Dim cbtn as MSforms.Commandbutton
Dim sRoot as String, i as Long
sRoot = "BaseName"
i = 1
for each oleobj in Activesheet.OleObject
if typeof oleObj.Object is MSForms.CommandButton then
set cbtn = oleObj.Object
cbtn.Caption = sRoot & i
'cbtn.name = sRoot & i
i = i + 1
end if
next

If you change the name (not the caption), any event code will need to be
changed to reflect the new name.
 
Thanks Tom, excuse my ignorance but where would I put the code.

Wildauk.
 
sub RenameBoxes()
Dim oleObj as Object
Dim cbtn as MSforms.Commandbutton
Dim sRoot as String, i as Long
sRoot = "BaseName"
i = 1
for each oleobj in Activesheet.OleObjects
if typeof oleObj.Object is MSForms.CommandButton then
set cbtn = oleObj.Object
cbtn.Caption = sRoot & i
'cbtn.name = sRoot & i
i = i + 1
end if
next
End Sub

Save the workbook.

Alt+F11 to get to the VBE
then Insert=>Module

paste the code in there

Alt+F11 to get back to Excel

Tools=>macro=>macros, select RenameBoxes (sheet with boxes shoud be the
active sheet.)

Hit the Run button.

If it screws things up, close the workbook without saving.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

Command Buttons 2
buttons 4
Button alinement 5
Command Button Question 8
Excel 2007 "Custom Toolbars Button" 2
Command button naming issue 1
A challenge 2
button names changed on copied sheet 4

Back
Top