Automatically Copy Macro to new Workbook

ebrandt

Board Regular
Joined
Dec 13, 2010
Messages
54
I have written a macro which moves selected worksheets to a new workbook and renames it.

I need the new workbook to include another macro I have written that sorts data in the worksheets.

How do I copy an existing macro to a new workbook within the macro that creates the new workbook?
 

Excel Facts

Back into an answer in Excel
Use Data, What-If Analysis, Goal Seek to find the correct input cell value to reach a desired result
Hi & welcome to the board.

Wouldn't it be easier to create a template blank workbook which already contains the code.

Then just open the template move the required sheets to it and save it under a new name.

Much simpler than trying to write code into the VBE at run-time in my opinion.
 
Upvote 0
Alternatively, you could copy the whole workbook (instead of just certain sheets), then delete the sheets in the copied workbook you don't want to keep.
 
Upvote 0

Forum statistics

Threads
1,223,249
Messages
6,171,031
Members
452,374
Latest member
keccles

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