This article has been archived. It is offered "as is" and will no longer be updated.
This article describes how to move Microsoft Visual Basic for Applications (VBA) code from one workbook to another.
If you want to move VBA code to a different workbook, you cannot move it directly like a worksheet. Instead, you must copy the code from the module in the original workbook, and then paste the code to a module in the other workbook.
To move VBA code to a different Microsoft Excel for Mac workbook, follow these steps:
Open the workbook that contains the macro module that you want to move.
Open the workbook to which you want to move the code, or open a new workbook.
On the Tools menu, point to Macro, and then click Visual Basic Editor.
In the Project window, select the project (workbook) in which you want to put the macro module. If the Project window is not visible, click Project Explorer on the View menu.
Note In Microsoft Excel X for Mac and later version, the Project window cannot be closed, and it is not available on the View menu.
On the Insert menu, click Module.
In the Project window, double-click the project that contains the existing macro.
Under the project, double-click the Modules folder, and then double-click the module below to open the code window for that module.
Select all of the code in the existing module and press COMMAND+C to copy it.
On the Window menu, click the new module that you created in step 5. Click inside that code window, and press COMMAND+V to paste the copied code in this new module sheet.
If you want to remove the original module, select the original module in the Project window; click Remove Module on the File menu, and when you are prompted, click Yes to delete the module.
If there are additional modules, repeat steps 4-10 to copy, paste, and (optionally) remove those modules from the original project.
On the File menu (this is the Excel menu in Excel X for Mac and later versions), click Close to return to Excel for Mac. Save both workbooks.
If a button or object is assigned to run the original macro and you have moved the code, reassign the button or object to the new macro location. To do this, hold down CONTROL, click the button or object, and then click Assign Macro on the shortcut menu. Look for the macro name and double-click that new macro location to reassign the button to that location.
XL2004 MacXLX Mac XLX XL2001 XL98 XL macro VB code program automation automated transfer copy add vba