Copy a macro module to another workbook

If a workbook contains a Visual Basic for Applications (VBA) macro that you would like to use elsewhere, you can copy the module that contains that macro to another open workbook by using the Visual Basic Editor (VBE).

Macros and VBA tools can be found on the Developer tab, which is hidden by default, so the first step is to enable it.

  • For Windows, go to File > Options > Customize Ribbon.

  • For Mac, go to Excel > Preferences... > Ribbon & Toolbar.

  • Next, in the Customize the Ribbon section, under Main Tabs, check the Developer check box.

Copying a module from one workbook to another

  1. Open both the workbook that contains the macro you want to copy, and the workbook where you want to copy it.

  2. On the Developer tab, in the Code group, click Visual Basic to open the Visual Basic Editor.

  3. In the Visual Basic Editor, on the View menu, click Project Explorer Project Explorer button image , or press CTRL+R .

  4. In the Project Explorer pane, drag the module containing the macro you want to copy to the destination workbook. In this case, we're copying Module1 from Book2.xlsm to Book1.xlsm.  

    VBA Project Explorer

  1. Module1 copied from Book2.xlsm

  2. Copy of Module1 copied to Book1.xlsm

Overview of macros and VBA

If you are unfamiliar with macros and VBA in general, you may find the following information helpful.

  • A macro is an action or set of actions that you can use to automate tasks.

  • You can record macros by using the Record Macro command on the Developer tab.

  • Macros are recorded in the VBA programming language.

  • You can inspect and edit your macros in the Visual Basic Editor, a window that is opened by Excel. Here's an example of the VBE window for Windows:

    A module that contains two macros stored in Module1 of Book1

Macros named MakeCellGreen and SetRowHeight are in a module named Module1, which is stored in Book1.

Need more help?

You can always ask an expert in the Excel Tech Community, get support in the Answers community, or suggest a new feature or improvement on Excel User Voice.

Connect with an expert
Contact us
Expand your skills
Explore training

Was this information helpful?

Thank you for your feedback!

Thank you for your feedback! It sounds like it might be helpful to connect you to one of our Office support agents.

×