Sign in with Microsoft
Sign in or create an account.
Select a different account.
You have multiple accounts
Choose the account you want to sign in with.

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.

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.

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, 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

Need more help?

You can always ask an expert in the Excel Tech Community or get support in the Answers community.

Need more help?

Expand your skills
Explore Training
Get new features first
Join Microsoft Office Insiders

Was this information helpful?

What affected your experience?

Thank you for your feedback!