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, "youpresent.co.uk" End Sub
All this does when the macro runs is show a simple message on your screen:
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:
- Start PowerPoint
- Press Alt+F11 to open the Visual Basic Editor (VBE)
- Right click on the VBAProject at the top left
- Click or hover over Insert
- Click Module
- 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
- Copy and past the macro from one of our posts to the code window on the right of the VBE
- Close the VBE
- Back in the main PowerPoint window, press Alt+F8
- 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.
I was looking for a Macro to measure the area of freeform shapes but the link to your list of these leads to a page that cannot be found. Is there anywhere I can find these elsewhere?
Where is the link that’s failing James? If you click on the search icon at the top of any page you can find any of our articles. This is the one you’re looking for http://youpresent.co.uk/calculating-area-powerpoint-freeform-shape/