VBA export worksheet not working correctly

Charmwah

Board Regular
Joined
Jan 23, 2017
Messages
64
Hi all

I recorded a macro to copy an existing worksheet into a new workbook, and assigned this to an existing button (form control) with text displayed as 'export report'. Once the duplicated worksheet is created in the new workbook the macro is also supposed to remove the button from the newly created copy. However, whats actually happening is that it only worked for the first button as its looking for "Button 1", but thats not the real issue. The real issue is that when the copy is made the original button in the original document no longer has the macro assigned to it?

My code is as follows:

Code:
Sub ExportRep()
'
' ExportRep Macro
'


'
    Sheets("Report").Select
    ActiveSheet.Buttons.Add(579.75, 135.75, 118.5, 40.5).Select
    Sheets("Report").Copy
    ActiveSheet.Shapes.Range(Array("Button 1")).Select
    Selection.Delete
End Sub

I'm not sure what i'm doing wrong. Might it be that I have to change the order of how i'm doing something, or when I assign the macro to the button?

Thanks in advance!
 

Excel Facts

Test for Multiple Conditions in IF?
Use AND(test, test, test, test) or OR(test, test, test, ...) as the logical_test argument of IF.
I've worked it out, the trick is to copy the worksheet without ​the button in the first place. Noob!
 
Upvote 0

Forum statistics

Threads
1,223,228
Messages
6,170,871
Members
452,363
Latest member
merico17

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