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

Convert text numbers to real numbers
Select a column containing text numbers. Press Alt+D E F to quickly convert text to numbers. Faster than "Convert to Number"
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,214,952
Messages
6,122,458
Members
449,085
Latest member
ExcelError

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