Copy/Paste with assigned macro

i_stoeva

New Member
Joined
Jun 7, 2006
Messages
29
Hi everybody,

Could someone tell me how to copy a toggle button with the assigned macro to it on other workbook?

Thanks,
Iva
 

Excel Facts

What is the last column in Excel?
Excel columns run from A to Z, AA to AZ, AAA to XFD. The last column is XFD.
If you copy the entire sheet, the code will also be copied.

It's easy to copy a control:

Code:
Sub Test()
    Dim WB1 As Workbook
    Dim WB2 As Workbook
    Dim Sh1 As Worksheet
    Dim Sh2 As Worksheet
    Set WB1 = Workbooks("Book1.xls")
    Set WB2 = Workbooks("Book2.xls")
    Set Sh1 = WB1.Worksheets("Sheet1")
    Set Sh2 = WB2.Worksheets("Sheet1")
    With Sh1.OLEObjects("ToggleButton1")
        .Copy
        Sh2.Paste Sh2.Range(.TopLeftCell.Address)
    End With
End Sub

but adding the code will involve using the Microsoft Visual Basic For Applications Extensibility library:

http://www.cpearson.com/excel/vbe.htm
 
Upvote 0

Forum statistics

Threads
1,225,726
Messages
6,186,674
Members
453,368
Latest member
xxtanka

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