Hello,
I'm trying to Copy 4 ActiveX CommandButtons from one Workbook, each named "CommandButton1", 2, 3 and 4"and Paste onto another. I have a code that successfully copies it over but if the Target Workbook already has a CommandButton1-4, the copied Button will continue in sequence and name itself "CommandButton5".
How can I ensure that all buttons are deleted from the Target Workbook and the new button is named the same as in the Source Workbook.
Here are the codes I use to delete all buttons in Source Workbook:
Here is the code to Copy buttons from Source to Target Worksheet:
Thanks much...
I'm trying to Copy 4 ActiveX CommandButtons from one Workbook, each named "CommandButton1", 2, 3 and 4"and Paste onto another. I have a code that successfully copies it over but if the Target Workbook already has a CommandButton1-4, the copied Button will continue in sequence and name itself "CommandButton5".
How can I ensure that all buttons are deleted from the Target Workbook and the new button is named the same as in the Source Workbook.
Here are the codes I use to delete all buttons in Source Workbook:
Code:
On Error Resume Next
ActiveSheet.DrawingObjects.Visible = True
ActiveSheet.DrawingObjects.Delete
On Error GoTo 0
Here is the code to Copy buttons from Source to Target Worksheet:
Code:
Source.Sheets("Journal Entry").Activate
ActiveSheet.Shapes.Range(Array("CommandButton1")).Select
Selection.Copy
Target.Sheets("Journal Entry").Activate
ActiveSheet.Paste
ActiveSheet.Shapes.Range(Array("CommandButton1")).Select 'this is where the code errors out since the Paste is renamed to CommandButton5
Set Button = ActiveSheet.Shapes("CommandButton1")
Button.Left = 622.5
Button.Top = 48
Thanks much...
Last edited: