Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Dynamically insert macro into a new excel workbook

Tags:

excel

vba

How can an existing macro be inserted into a new excel workbook?

I want to create a new WorkBook (with vba), and then place an existing macro into the new WorkBook.

like image 506
elkbullwinkle Avatar asked Dec 26 '11 11:12

elkbullwinkle


People also ask

How do I add a macro to a new workbook?

Open both the workbook that contains the macro you want to copy, and the workbook where you want to copy it. On the Developer tab, click Visual Basic to open the Visual Basic Editor. , or press CTRL+R . In the Project Explorer pane, drag the module containing the macro you want to copy to the destination workbook.

How do I make a macro available in all workbooks?

Go to Files > Options > Add-in and select the above Excel file/Macro from the list of Inactive Application Add-ins & Click Go. This step makes the function/macro available for all workbook.


1 Answers

The two options that JMax mentioned:

"hard way"

  • Pearson's Copy a module from one project to another

"easy way"

  • Use your existing workbook with the UserForm as a template to create the new WorkBook
    1. Save the existing workbook as is (to preserve your current file)
    2. Strip out any unwanted sheets
    3. If you need to strip out any code then you are effectively back to the first option as you will need Pearson's Deleting A Module From A Project / Deleting A Procedure From A Module
    4. Save as a new file

We would need to see a sample of your workbook to provide further detailed help.

like image 106
brettdj Avatar answered Oct 17 '22 20:10

brettdj