ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   How to copy commandbuttons (https://www.excelbanter.com/excel-programming/368248-how-copy-commandbuttons.html)

leonidas[_51_]

How to copy commandbuttons
 

Hi,

I have a worksheet (sheet1) with four commandbuttons on row1 and I have
added a new worksheet (sheet2). When I unprotect sheet1, activate the
button "Design Mode" on the "Control Toolbox" toolbar, copy row1 and
paste it as row1 on sheet2, the commandbuttons are also copied.
When I record this with the macro recorder (see code below) and play
the macro afterwards it copies row1 but the commandbuttons are NOT
copied.
What do I need to change to also copy these commandbuttons? Thanks in
advance!


Code:
--------------------
Sheets("Sheet1").Select
Sheets.Add
Sheets("Sheet1").Select
ActiveSheet.Unprotect
Rows("1:1").Select
Selection.Copy
Sheets("Sheet2").Select
Rows("1:1").Select
ActiveSheet.Paste
--------------------


--
leonidas
------------------------------------------------------------------------
leonidas's Profile: http://www.excelforum.com/member.php...o&userid=35375
View this thread: http://www.excelforum.com/showthread...hreadid=564659


Bernie Deitrick

How to copy commandbuttons
 
leonidas,

Use the commandbuttons from the Forms commandbar, rather than the commandbuttons from the Control
Toolbox. You will need to assign a macro rather than use a click event, but the forms
commandbuttons can have their properties set to be moved and sized with a range, which makes them
'copy-able' through code.

HTH,
Bernie
MS Excel MVP


"leonidas" wrote in message
...

Hi,

I have a worksheet (sheet1) with four commandbuttons on row1 and I have
added a new worksheet (sheet2). When I unprotect sheet1, activate the
button "Design Mode" on the "Control Toolbox" toolbar, copy row1 and
paste it as row1 on sheet2, the commandbuttons are also copied.
When I record this with the macro recorder (see code below) and play
the macro afterwards it copies row1 but the commandbuttons are NOT
copied.
What do I need to change to also copy these commandbuttons? Thanks in
advance!


Code:
--------------------
Sheets("Sheet1").Select
Sheets.Add
Sheets("Sheet1").Select
ActiveSheet.Unprotect
Rows("1:1").Select
Selection.Copy
Sheets("Sheet2").Select
Rows("1:1").Select
ActiveSheet.Paste
--------------------


--
leonidas
------------------------------------------------------------------------
leonidas's Profile: http://www.excelforum.com/member.php...o&userid=35375
View this thread: http://www.excelforum.com/showthread...hreadid=564659





All times are GMT +1. The time now is 10:55 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com