Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 36
Default command buttons

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.
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default command buttons

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.

--
regards,
Tom Ogilvy


"wildauk" wrote in message
...
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.



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 36
Default command buttons

Thanks Tom, excuse my ignorance but where would I put the code.

Wildauk.

"Tom Ogilvy" wrote:

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.

--
regards,
Tom Ogilvy


"wildauk" wrote in message
...
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.




  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default command buttons

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.

--
Regards,
Tom Ogilvy

"wildauk" wrote in message
...
Thanks Tom, excuse my ignorance but where would I put the code.

Wildauk.

"Tom Ogilvy" wrote:

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.

--
regards,
Tom Ogilvy


"wildauk" wrote in message
...
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.






Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Command Buttons msals22[_3_] Excel Programming 2 June 21st 06 09:43 PM
command buttons Natalie Excel Worksheet Functions 1 March 7th 05 01:45 PM
Command buttons Russell Stevenson Excel Programming 3 November 12th 03 02:57 AM
Control Buttons vs. Command Buttons Robert Gibson Excel Programming 1 October 13th 03 04:33 PM
Command buttons not available Donna Brooks Excel Programming 0 August 25th 03 04:23 PM


All times are GMT +1. The time now is 04:49 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"