You probably already recognise Microsoft Office as a powerful suite of applications designed to make your working day productive and, dare I say it, even fun! But did you know you can get even more out of Microsoft Office applications through automation solutions?
PowerPoint is an awesome tool for creating your latest presentation template but if you’re the person responsible for creating them in your organisation, you’ll know that PowerPoint often behaves like a badly-behaved monkey. I’m going to walk you through the pitfalls of slide master layouts and show you how to manage them and recover any deleted default Office layouts using VBA.
Why are layouts in PowerPoint so important?
Layouts define how your content is consistently laid out on the slide in a way that respects your brand. Each layout uses a set of content placeholders and each placeholder, depending on its type, may contain text, pictures, video or more complex content such as tables, charts and SmartArt.
Backing up a bit, any and every presentation you create is based on a template, often deployed as a potx file, and each template contains all the slide masters and layouts used to keep your visual content on-brand.
If you only ever work with one template, then your life will be filled with smiles and sunshine. However, the monkey in PowerPoint comes to life when you work with presentations that have been built on different templates. This is very common in organisations that have issued revisions to templates either to make minor corrections and design tweaks or as a result of a more significant rebranding program.
What often happens is that the old template doesn’t contain the same number, identity or type of layouts as in the new template. Now, when you copy content from your old presentation based on the old template to your new presentation based on the new template, PowerPoint tries to work out how to reassign each slide to a layout. Sometimes it works, but more often it fails. When it fails, PowerPoint has no choice but to create a new layout or even worse in some cases, a new master with many layouts in your presentation file. But you probably won’t notice until your file size is bloated, or someone asks you why your slides are no longer on-brand.
You can see when this happens as layouts are either added with an unfamiliar name, taken from the old master, or are prefixed with a number and underscore:
These erroneous layouts and/or masters are often referred to as orphaned layouts and masters. An orphaned master in the above example might be named “1_Office Theme” and if multiple erroneous masters have been created “2_Office Theme”, “3_Office Theme” and so on to infinity and beyond.
If your slide master includes images, this behaviour can make your presentation files very big, no, huge, over time and more importantly, impact the consistency of your brand.
Now you might ask what criteria PowerPoint uses to map one slide’s layout to another. You might assume that it uses the name of the layout such as “Title and Content” but it’s not as simple as that unfortunately. Behind the scene, there is a lot of hidden information about a layout that you and I can’t see in PowerPoint and it must match all of the following properties before it correctly maps a layout to a slide:
- Slide Layout Name
- Slide Layout Type* (hidden data in the PowerPoint file)
- Number of Placeholders
- Types of each Placeholder e.g. title, body, footer etc.
- Placeholder Unique Identities* called “idx” (hidden data in the XML of the PowerPoint file)
* This information is not accessible to you and if you delete placeholders or layouts from the master, you can seriously mess up your template, breaking it beyond [easy] repair.
And that’s why layouts, the creation and management of them are so important.
Assigning layouts to slides in PowerPoint
You assign a layout to a slide by going to the Home tab and clicking the Layout drop down and then clicking the most appropriate layout design for your intended slide content:
You can also right-click on an unoccupied area of the slide and click Layout from menu:
In the example above I’ve used the default Microsoft Office template and for Office 365, it includes nine default layouts. You might see eleven depending on your version of PowerPoint or more if you have a custom template.
Once a layout is assigned to a slide, it encourages the use of consistent positioning, sizing and styling of the content you populate the slide with. I say “encourage” because you can always break it and go off-brand with your creative muscle. If you do and you didn’t mean to, simply click the Home tab and click the Reset button in the Slides group or do the same with a right-click on an unoccupied area of the slide and click Reset Slide:
All your content will be snapped back into position, size and styled according to the assigned layout.
Editing layouts in PowerPoint
You can view and edit all the layouts in the slide master by going to the View tab and click Slide Master:
You can also hold the Shift key and click on the Normal button in the PowerPoint status bar:
Single clicking this button takes you to the layout assigned to the current slide and double clicking it takes you what’s often referred to as the slide master parent.
Once in the Slide Master view you’ll see the layouts below the slide master parent:
The parent contains the default style for the title, body, date, footer and slide number placeholders. It may also include common background pictures such as a brand logo, graphics and photography.
Importantly, all the layouts below the parent follow the style of the parent. They are linked to the parent by default, but this link can be easily broken if you do things like deleting content from the layouts.
And because each layout is referred to by PowerPoint when you copy and paste content from one presentation to another, should you delete the layout, the PowerPoint monkey will get confused and start bloating your file with orphaned layouts and/or masters. This is a dark doorway to a PowerPoint nightmare I wouldn’t wish on anyone!
Restoring deleted slide master layouts in PowerPoint
Let’s assume that someone has deleted the Title and Content layout from your template’s slide master. You might assume you can simply fix this by inserting a new layout, naming it “Title and Content” and inserting the required placeholders. Earlier, you learned that PowerPoint uses more than just the name to match slides to layouts. It’s no surprise therefore that trying to fix your template this way won’t work. So, what’s the solution?
Are you ready to delve into the world of VBA to fix your template? It’s very easy and I’ll take you step-by-step through the process next.
What is VBA?
Visual Basic for Applications is a programming environment for Microsoft Office applications. It’s included with your installation of Office by default unless your system administrator has deactivated it. VBA provides you with a way to automate PowerPoint and extend its functionality using macros and add-ins. I’m going to use it to automatically restore the missing default layouts that come with Microsoft’s default PowerPoint template.
Opening the magical door to the wizardry of VBA
Getting to meet your VBA friend is very simple. With PowerPoint open and at least one presentation file open, press Alt+F11* on your keyboard. This will open the VBE (Visual Basic Editor):
*If for some reason Alt+F11 isn’t mapped on your keyboard you can right click anywhere on the ribbon, select Customize the Ribbon… and in the window that appears, tick the Developer Tab check box over on the right hand side before clicking OK to close the window. Now you can click the Visual Basic button within this tab:
Adding VBA code
To add some VBA code, you need a container to put it in so go ahead and click Insert from the menu and then select Module:
You now have a module ready to paste the VBA code into that I’ll provide below:
Copy the VBA code from below by double-clicking on it and then paste it into the Module1 window above.
Option Explicit '---------------------------------------------------------------------------------- ' PowerPoint VBA Macro to restore any missing default Office layouts '---------------------------------------------------------------------------------- ' Copyright (c) 2019 BrightCarbon Ltd. All Rights Reserved. ' Source code is provided under Creative Commons Attribution License ' This means you must give credit for our original creation in the following form: ' "Includes code created by BrightCarbon Ltd. (brightcarbon.com)" ' Commons Deed @ http://creativecommons.org/licenses/by/3.0/ ' License Legal @ http://creativecommons.org/licenses/by/3.0/legalcode '---------------------------------------------------------------------------------- ' Purpose : Rebuilds the slide master by inserting slides assigned to the default ' Office template layouts before deleting those slides, resulting in the ' layouts remaining intact within the slide master. ' Author : Jamie Garroch ' Date : 08APR2019 ' Website : https://brightcarbon.com/ '---------------------------------------------------------------------------------- Sub RestoreDefaultLayouts() With ActivePresentation.Slides .Add(.Count + 1, ppLayoutTitle).Delete ' Title Slide (slideLayout1.xml type="title") .Add(.Count + 1, ppLayoutObject).Delete ' Title and Content (slideLayout2.xml type="obj") .Add(.Count + 1, ppLayoutSectionHeader).Delete ' Section Header (slideLayout3.xml type="secHead") .Add(.Count + 1, ppLayoutTwoObjects).Delete ' Two Content (slideLayout4.xml type="twoObj") .Add(.Count + 1, ppLayoutComparison).Delete ' Comparison (slideLayout5.xml type="twoTxTwoObj") .Add(.Count + 1, ppLayoutTitleOnly).Delete ' Title Only (slideLayout6.xml type="titleOnly") .Add(.Count + 1, ppLayoutBlank).Delete ' Blank (slideLayout7.xml type="blank") .Add(.Count + 1, ppLayoutContentWithCaption).Delete ' Content with Caption (slideLayout8.xml type="objTx") .Add(.Count + 1, ppLayoutPictureWithCaption).Delete ' Picture with Caption (slideLayout9.xml type="picTx") .Add(.Count + 1, ppLayoutVerticalText).Delete ' Title and Vertical Text (slideLayout10.xml type="vertTx") removed from O365 .Add(.Count + 1, ppLayoutVerticalTitleAndText).Delete ' Vertical Title and Text (slideLayout11.xml type="vertTitleAndText") removed from O365 End With End Sub
You should now see something like this:
Because this code is just a single Sub procedure called RestoreDefaultLayouts, it’s referred to as a macro.
Now this isn’t an article aimed at explaining how to program in VBA but briefly, this is what the macro does:
- Creates a temporary slide at the end of the presentation using each of the default layouts, deleting the temporary slide after each operation.
- This action forces PowerPoint to recreate any missing layouts in the master with all the necessary hidden data not available to me or you.
Running the VBA Macro
Now you have the macro in your presentation you can use Alt+Tab to return to the more familiar PowerPoint window. From here, the macro can be run by pressing Alt+F8 on your keyboard which opens a window containing a list of available macros:
Select the RestoreDefaultLayouts macro and then click the Run button. The macro will do its magic, recreating any missing default Office layouts in your slide master.
Once you’re all done, you can go back to the VBE and right click on the VBA module to delete it. You need to do this as VBA can’t be saved with pptx files and you won’t want to send your presentation as a pptm file, the type that supports embedded VBA code.
So, there you have it. A quick an easy way to get your default Office Theme layouts back in your slide master, saving hours of head-scratching.
For more on constructing a PowerPoint deck check out our templates and masters resource. We also have a few great tools to help you with the technical side of PowerPoint, like this video embedding tool to help you find out what type of videos will run for you, this step-by-step guide to compressing PowerPoint presentations, and our brilliant guide to PowerPoint grids.
Leave a comment
Senior technical consultantView Jamie Garroch's profile
PowerPoint has evolved into an app which is the Swiss Army knife of content creation, not only for presentations but also printed collaterals, videos and even interactive presentations. In this second part of our series on supercharging PowerPoint interactive presentations with VBA we look at how you can provide your users with visual feedback for active areas of your slide using a mouse hover technique.
PowerPoint has evolved into an app which is the Swiss Army knife of content creation, not only for presentations, but also printed collateral, videos and even interactive presentations. In this article learn how you can add links to objects on slides that, when clicked, take the user to a different slide.
A big and sincere thanks for all of your superb help and effort in preparing such fantastic material and for all your excellent coaching tips. Look forward to working with you again soon.Greg Tufnall Siemens