Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 28
Default Button controls on worksheets

I have a worksheet with 4 command buttons. I wrote a macro to copy the entire worksheet to a new workbook (along with the macros referring to the command buttons). However, once I have copied the worksheet, the name of the command buttons changed to "commandbutton1", "commandbutton2", ... etc. For that reason, it won't read the orginial macros anymore (because the codes were written for the buttons with the orginal names). How do I change them back to the orginal names?
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 770
Default Button controls on worksheets

Anson,

It would be helpful to see the code that does the copying. The code:

sheet1.copy

copies a sheet with button names intact.

hth,

Doug Glancy

"Anson" wrote in message
...
I have a worksheet with 4 command buttons. I wrote a macro to copy the

entire worksheet to a new workbook (along with the macros referring to the
command buttons). However, once I have copied the worksheet, the name of the
command buttons changed to "commandbutton1", "commandbutton2", ... etc. For
that reason, it won't read the orginial macros anymore (because the codes
were written for the buttons with the orginal names). How do I change them
back to the orginal names?


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Button controls on worksheets

Dim cBtn as MSForms.CommandButton
vArr = Array("btn1", "btn2", "btn3", "btn4")
Dim b as OleObject

i = lbound(varr)
for each b in ActiveSheet.OleObjects
if type of b is msforms.commandbutton then
set cBtn = b.Object
cBtn.Name = vArr(i)
i = i + 1
end if
Next


--
Regards,
Tom Ogilvy



"Anson" wrote in message
...
I have a worksheet with 4 command buttons. I wrote a macro to copy the

entire worksheet to a new workbook (along with the macros referring to the
command buttons). However, once I have copied the worksheet, the name of the
command buttons changed to "commandbutton1", "commandbutton2", ... etc. For
that reason, it won't read the orginial macros anymore (because the codes
were written for the buttons with the orginal names). How do I change them
back to the orginal names?


  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Button controls on worksheets

Not in Excel 97. The names are changed to default names. Fixed in Excel
2000 and later.

--
Regards,
Tom Ogilvy

"Doug Glancy" wrote in message
...
Anson,

It would be helpful to see the code that does the copying. The code:

sheet1.copy

copies a sheet with button names intact.

hth,

Doug Glancy

"Anson" wrote in message
...
I have a worksheet with 4 command buttons. I wrote a macro to copy the

entire worksheet to a new workbook (along with the macros referring to the
command buttons). However, once I have copied the worksheet, the name of

the
command buttons changed to "commandbutton1", "commandbutton2", ... etc.

For
that reason, it won't read the orginial macros anymore (because the codes
were written for the buttons with the orginal names). How do I change them
back to the orginal names?




  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 770
Default Button controls on worksheets

Thanks, Tom.

Doug

"Tom Ogilvy" wrote in message
...
Not in Excel 97. The names are changed to default names. Fixed in Excel
2000 and later.

--
Regards,
Tom Ogilvy

"Doug Glancy" wrote in message
...
Anson,

It would be helpful to see the code that does the copying. The code:

sheet1.copy

copies a sheet with button names intact.

hth,

Doug Glancy

"Anson" wrote in message
...
I have a worksheet with 4 command buttons. I wrote a macro to copy the

entire worksheet to a new workbook (along with the macros referring to

the
command buttons). However, once I have copied the worksheet, the name of

the
command buttons changed to "commandbutton1", "commandbutton2", ... etc.

For
that reason, it won't read the orginial macros anymore (because the

codes
were written for the buttons with the orginal names). How do I change

them
back to the orginal names?








  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 28
Default Button controls on worksheets

Hi Tom,

Thanks for you help!

"Tom Ogilvy" wrote:

Dim cBtn as MSForms.CommandButton
vArr = Array("btn1", "btn2", "btn3", "btn4")
Dim b as OleObject

i = lbound(varr)
for each b in ActiveSheet.OleObjects
if type of b is msforms.commandbutton then
set cBtn = b.Object
cBtn.Name = vArr(i)
i = i + 1
end if
Next


--
Regards,
Tom Ogilvy



"Anson" wrote in message
...
I have a worksheet with 4 command buttons. I wrote a macro to copy the

entire worksheet to a new workbook (along with the macros referring to the
command buttons). However, once I have copied the worksheet, the name of the
command buttons changed to "commandbutton1", "commandbutton2", ... etc. For
that reason, it won't read the orginial macros anymore (because the codes
were written for the buttons with the orginal names). How do I change them
back to the orginal names?



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
How to Add NamedRange Controls to Worksheets? lijipan Excel Worksheet Functions 0 November 16th 07 04:40 PM
Command Button Active X controls Kenny Excel Discussion (Misc queries) 1 October 2nd 07 02:39 AM
Controls in all worksheets are suddenly invisible Sabba Excel Discussion (Misc queries) 1 October 28th 06 01:51 AM
Deleting worksheets containing ActiveX controls Alex[_24_] Excel Programming 4 May 10th 04 08:51 AM
Programmatically Adding Controls (Macro) eg Button on A SpreadSheet Martin SChukrazy Excel Programming 0 March 7th 04 06:01 AM


All times are GMT +1. The time now is 01:35 AM.

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"