Copy macros between workbooks
- 1Open both workbooks: Macros.xlsm (has the macro) and Log.xlsm (needs it).
- 2Alt+F11 for the Visual Basic Editor; Ctrl+R if the Project pane is hidden.
- 3Drag the module Stamps from VBAProject (Macros.xlsm) onto VBAProject (Log.xlsm).
- 4Close the editor and save Log.xlsm as a macro-enabled .xlsm.
A macro lives in a module, so you copy the module. Dragging it onto the other workbook's project copies it and leaves the original where it was.
What the MO-211 task asks
Our MO-211 practice exams do not test this one yet: each download is a single workbook, and copying a macro needs a second one to copy from. We say so rather than guess at the wording of a real-exam task.
A task for it has to name both workbooks and the macro or module, for example: copy the StampDate macro from Macros.xlsm into Log.xlsm. Whatever the wording, the result that counts is the module inside the destination workbook, saved in a format that keeps it.
Running another workbook's macro is not the same thing. Alt+F8 lists the macros of every open workbook, so StampDate can run on Log while Macros.xlsm is open; once Macros.xlsm closes, Log has nothing.
Worked examples
Set up the grid below to follow along. Each example starts from it as shown; every result is what Excel showed.
| A | B | C | D | |
|---|---|---|---|---|
| 1 | Vessel | Berth | Fee | |
| 2 | Osprey | B4 | 90 | |
| 3 | Tern | C2 | 180 |
- 1Open Macros.xlsm and Log.xlsm. Alt+F11.
- 2In the Project pane, drag Stamps (under Macros.xlsm › Modules) onto VBAProject (Log.xlsm).
- 3Back in Excel, on Log: Alt+F8, StampDate, Run.
The copy is a module of Log's own, with the same name and code. The source keeps its module.
- 1After copying, close Macros.xlsm.
- 2On Log: Alt+F8, StampDate, Run.
This is the test that you copied the macro rather than borrowed it: it still runs with the other workbook closed.
- 1In the editor, right-click Stamps (Macros.xlsm) › Export File, and save Stamps.bas.
- 2Select VBAProject (Log.xlsm), then File › Import File, and pick Stamps.bas.
The same result through a file, useful when the two workbooks cannot be open together.
- 1Import Stamps.bas into Log a second time.
- 2Alt+F8, StampDate, Run.
The second copy gets a new module name, but both hold a StampDate, and Excel will not run an ambiguous name. Remove the extra module.
- 1Alt+F11, drag Stamps onto VBAProject (copy-macros.xlsm).
- 2Close the editor; Alt+F8, StampDate, Run.
The first example, done in Excel with both workbooks open. In the video the Log workbook is saved as copy-macros.xlsm, so that is the project name you see.
Watch it done in Excel
The last example above, recorded in real Excel on the same grid.
Exam traps
An .xlsx cannot hold macros. Saved as .xlsx, Log loses the copied module: reopened, it has no macros at all. Keep it .xlsm.
Running 'Macros.xlsm'!StampDate from the Macros list while both files are open changes Log, but copies nothing. Check the module is listed under VBAProject (Log.xlsm).
Dragging or importing twice adds Stamps1 beside Stamps, and StampDate then refuses to run. Remove the extra module.
FAQ
Does copying a module move it?
No. The source workbook keeps its module; the destination gets its own copy.
Can I copy just one macro out of a module?
Yes: copy its lines from Sub to End Sub in the code window and paste them into a module in the other workbook. Dragging copies the whole module.
Do the copied macros need the source workbook open?
No. Once copied, the macro runs with the source closed.
Try it under exam conditions
Take a full, timed MO-211 practice exam, upload the workbook you built, and get a score out of 1000 with a per-task breakdown of where the points went. Your first one is free.
No credit card needed.
