Using Project Macros

To use Macros in Project you need to store them in a module. Doing this requires opening the Visual Basic Editor (aka: VBE). To open the VBE, first open project and then hit the ALT and F11 keys together to open the editor. You can also reach the editor by going to Tools menu / Macro / Visual Basic Editor

Once the VBE is open there are two ways to store the macros.

The first was is to import the file. Do this by first selecting the project you want to import into. You do this by selecting one of the projects in the project explorer window (this window is in the upper left corner typically). If you are going to use the macro for all projects then I would recommend that you select the "Global.mpt" project. This makes the macro available for any file you have open on your computer. If you are going to distribute the macro then perhaps you might pick an individual file that you may be sharing with others. Once you have selected the destination (just highlight it) go to the file menu, select "Import File" then browse for the file. Clicking open will create a new module within the selected project. Double clicking on the module will open it and display the code.

The second way is to cut and paste. To do this either insert a new module into a selected project (select the same as above) or open an existing module and paste the code in. If you are using this method then you will want to comment out (by putting an apostrophe at the beginning of the line) or delete the line that starts with "Attribute".

If you are pasting, be careful for line wrapping.

If the macro interacts with Excel it will need to reference the Excel object library set in order to run correctly.
If you run the macro and and get an error please try the following: Open Project. ALT+F11 to open the Visual Basic Editor From the Tools menu select "References". Scroll down until you see the Microsoft Excel Object Library (or something similar). Make sure the box next to it is checked.

Back to Macros Page

Send me mail at: