Leading the way in Microsoft Office Development
 Home|Excel|Word|PowerPoint|Consultancy|Feedback|Contact 
 Microsoft PowerPoint > Macros > Recording a Macro< Previous | Next > 

 

Step 1 - Rehearse what you want to Record

 
 

The Macro Recorder can be used to record simple macros.

 
 

Recording macros is very useful even if you are a very experienced programmer, although there are some limitations that you need to be aware of.

 
 

If you are relatively new to macros it is worth rehearsing your steps first before recording them.

 
 

This will help you to understand the code that is generated and to help make your code as efficient as possible.

 
 

When you record a macro PowerPoint is basically recording the keystrokes, menu commands exactly as they are pressed.

 
 

After you have recorded a few single steps you can run the macro to perform the required task again and again.

 
 

Once you start the Macro Recorder all your keystrokes will be recorded and converted into VBA code.

 
 

Before recording your macro check your macro security level. You will be not be able to record a macro if your security level is set to High. This should be changed to Medium.

 

 

Step 2 - Record your Macro

 
 

Select (Tools > Macro > Record New Macro) to display the Record Macro dialog box.

 
 

Alternatively you could press the "Record Macro" button on the Visual Basic toolbar.

 
 

 (Tools > Macro > Record New Macro) dialog box

 
 

The name of your macro will automatically default to "Macro1", "Macro2", etc depending on the number of macros that have been recorded in that specific presentation.

 
 

Macro names must begin with a letter.

 
 

Macro names cannot include spaces although the underscore character can be used (e.g. "macroname_2"). You can also include numbers in your macro names.

 
 

The description is optional so do not worry about this at this point, however it is very important to remember where your macro will be stored.

 
 

It is not currently possible to assign shortcut keys to your macros, although this is discussed in more detail in the Finishing Touches page.

 

 

Step 3 - Where to store your macro

 
 

The only place you can store your macros is in the active presentation. Don’t panic though as you can move the code after it has been recorded.

 
 

There is no equivalent of a "Personal.xls" or a "Normal.dot" in PowerPoint so for the time being

 
 

Once you press OK a small floating toolbar will appear. This is the Stop Recording toolbar and indicates that any keystrokes you make will be recorded.

 
 

You can now perform the keystrokes that you would like to be automated.

 
 

A new code module is often inserted into the active presentation automatically to contain the generated VBA code.

 
 

If the macro is only going to be used in one presentation then you can store the VBA code in that particular presentation.

 
 

If you want the macro to be available in every presentation that is based on a particular template, then you should store the VBA code in the template file ".pot".

 
 

If you want your macros to be available for every open presentation it is possible to create an add-in. For more information about how to create an add-in, please refer to the Add-ins section.

 

 

Step 4 - Stop Recording

 
 

You can stop recording by selecting (Tools > Macro > Stop Recording) or by pressing the Stop Recording button on the left hand side of the Stop Recording toolbar.

 
 

 Stop Recording toolbar

 
 

The toolbar will then disappear.

 
 

It is very important to stop recording once you have finished otherwise PowerPoint will carry on recording your keystrokes indefinitely.

 
 

Once you have finished recording you can cut and paste the code (via the clipboard) to different code modules.

 

 

Step 5 - Viewing the Code

 
 

The only way to view the VBA code is through the Visual Basic Editor window.

 
 

This window can be displayed by selecting (Tools > Macro > Visual Basic Editor) or by pressing (Alt + F11).

 
 

 Visual Basic Editor, Project Explorer window

 
 

You will need to locate the Project in the Project Explorer window. This should appear in the top left corner. If you cannot see it, select (View > Project Explorer).

 
 

There should be a project there called VBAProject followed by the name of the presentation in brackets. Expand this project.

 
 

Select the Modules node and expand it. There should be a module called "Module 1". Double click this module to display the code window.

 
 

Your macro will appear here and all the VBA code is contained within the "Sub" and "End Sub" statements.

 
 

You will often find that the Macro Recorder will generate more code than you really need although it is easy to remove any unnecessary code.

 

 

Step 6 - Things to Remember

 
 
  • The code that is generated is normally very specific and often dependent on local settings or options.

     
     
  • It is not possible to record a macro and have the generated code placed within an existing macro. You will have to cut and paste the lines of code manually.

     
     
  • The code generated by the macro recorder often contains a lot of unnecessary arguments and lines and should really be cleaned up afterwards.

     
     
  • Be aware that the Macro Recorder cannot create any of the following: Loops, Variables, Error Handling or Conditional statements.

     
     
  • The code generated by the macro recorder can often be quite inefficient and will run quite slowly compared to code that has been optimised.

     

     Copyright © 2004-2007 Better Solutions Limited. All Rights Reserved.< Previous | Top | Next >