Select Page

What’s a VBA Macro?

Put simply, a VBA macro (see tech talk below) is a small program containing a set of instructions for a Microsoft Office application such as PowerPoint, Excel or Word to carry out. The macro travels around with your document so anyone who has access to the document can use the VBA macro(s) in it.

VBA, or Visual Basic for Applications, is the language that these instructions are written in and the VBA environment is included with Microsoft Office for the PC and Mac, although your IT team can choose not to install it.

Macros can be as simple as a few lines of code or form the basis of large enterprise scale projects, even commercial add-ins.

Before we go any further, here’s a really simple example:

Sub HelloWorld()
  MsgBox "Hello World!", vbInformation, ""
End Sub

All this does when the macro runs is show a simple message on your screen:

VBA Macro - Hello World

Creating a Macro

The subject of VBA is big, huge, massive. So the purpose of this post is not to teach you how to write VBA macros but to equip you with the knowledge to reuse various macros which we’ve published on this site.

The macros we write are plain text so all you need to do is copy them from the post into your PowerPoint presentation (did we mention that macros travel with your presentation?).

Here’s the steps you need to copy the macro into your project in PowerPoint for the PC or Mac:

  1. Start PowerPoint
  2. Press Alt+F11 to open the Visual Basic Editor (VBE)
    Macro Guide - VBE 1
  3. Right click on the VBAProject at the top left
  4. Click or hover over Insert
  5. Click Module
    Macro Guide - VBE 2
  6. This will insert a code module into the VBA project of your presentation and you can see the white code window on the right hand side of the screen
    Macro Guide - VBE 3
  7. Copy and past the macro from one of our posts to the code window on the right of the VBE
    Macro Guide - VBE 4
  8. Close the VBE
  9. Back in the main PowerPoint window, press Alt+F8
    Macro Guide - VBE 5
  10. A list of the available [public] macros is shown and you can select the one you want and click Run to, well, run it!

Where Can I Get YOUpresent Macros?

Now you’re at the best bit! We are always writing new macros so check out this VBA blog category to browse everything we have available. Don’t forget that we provide these under the Creative Commons license which means we just need you to credit us for the original work.

Open our VBA Macro Blog in a new tab/window

Tech Talk

VBA defines two types of procedures, a Sub and a Function. In addition, these two procedures may be defined as being Public (the default) or Private. Here are examples of the four combinations:

Public Sub Test1()
  ' Your code goes here
End Sub

Private Sub Test2()
  ' Your code goes here
End Sub

Public Function Test3()
  ' Your code goes here
End Function

Private Function Test4()
  ' Your code goes here
End Function

A VBA Macro only refers to a Public Sub procedure (note that if the Public or Private keyword is omitted, the procedure is assumed to be Public). A Function procedure cannot be called from the run macro window (Alt+F8) and neither can a Private Sub. That’s why VBA is not synonymous with “a macro”. VBA is a much larger topic than macros alone.