Microsoft PowerPoint - set font and language for a whole presentation#

The script presented here is written in Visual Basic for Applications (VBA), the programming language coming with Microsoft Office. VBA is mostly used to manipulate data in Excel sheets, but here, we will use it to set the font type and language of a whole Microsoft PowerPoint presentation to the same values.

This may be helpful if you use more than one language on your PC and the standard is set to another than the desired language, or you decide to change the font size in a whole presentation.

The method applied here can be extended in a variety of ways to manipulate other things, like background color, font size, or position, among others. You just need to adapt the properties and scope used.

Requirements#

To run the script, the following is needed:

  • a Microsoft PowerPoint presentation to test the script with

  • a running version of Microsoft PowerPoint

Code#

We will first create a script to do the language and font standardization, save it somewhere, load it into a presentation, and finally run it.

Create a VBA script#

To create a VBA script, open MS PowerPoint and press ALT + F11, the shortcut to open the built-in VBA editor.

Go to the project explorer on the upper left of the window. Right-click on the name of your current presentation and select Insert and then Module. A blank sheet will appear in the main window of the VBA editor.

Then, copy and paste the following code block into the empty sheet:

Sub CorrectLanguageAndFont()

    i = 1
    For Each slide1 In ActivePresentation.Slides
        Debug.Print (slide1.Name & " - " & i)
        For Each shape1 In slide1.Shapes
            If shape1.HasTextFrame = True Then
                shape1.TextFrame.TextRange.LanguageID = msoLanguageIDEnglishUS
                shape1.TextFrame.TextRange.Font.Name = "Lato"
            End If
        Next
        i = i + 1
    Next

End Sub

This is the whole code needed. The following explanation details the code line by line. It is not necessary if you just want to run the code quickly, but may be helpful to understand and modify it to your needs.

Code details#

A script in VBA is started and ended with Sub and End Sub. That means that various scripts can be arranged in one document, but at each time, only one script is run.

After starting a new script, the variable i is set to one. It will represent the slide or page number in the PowerPoint presentation.

Then, a for loop is using the For Each and Next statements. In VBA for Microsoft PowerPoint, all elements of a presentation are organised as objects that contain other objects. The parent or root object in the currently opened presentation is called ActivePresentation. Its children are the slides, accessed with ActivePresentation.Slides, and the for loop goes through all of them, assigning the name slide1 to the slide in the current iteration of the loop.

The Debug.Print () command is used to print the current slide’s name and number to monitor the progress of the script.

The second loop nested inside the first one iterates over the objects found in a single slide, and they are called Shapes. The name shape1 is assigned to the shape in the current iteration of the loop.

Using the shape1.HasTextFrame property we now test whether the current shape actually has text in it. Remember that text can be found not only in text boxes, but can also be added to many other elements.

Finally, if text is found, we modify two properties: The language and the font type. They can be accessed with shape1.TextFrame.TextRange.LanguageID and shape1.TextFrame.TextRange.Font.Name. The values used here represent some commonly used ones, but you may look at the Microsoft VBA documentation on language IDs for an exhaustive list of language codes. The font name is just given as a string value equaling the name in the font selection menu of Microsoft PowerPoint.

Check the Microsoft VBA documentation for TextRange properties to get an idea of what else can be modified.

Export the VBA script#

We recommend you save and export your script at this point. This will allow for re-using your script, sharing it, and keeping it separated from individual presentations and your current Microsoft PowerPoint version. To export, right-click on the module you created before and select File export. Then save the file at the location of your choice. The file extension of VBA macros is .bas. We are now ready to apply our script to any Microsoft PowerPoint presentation.

Load the script into a presentation#

To run the script, we first open a presentation in MS PowerPoint. Then, we open the VBA editor pressing ALT + F11. Again, we select our presentation in the project explorer in the upper left and select Import file.... We then navigate to the script we saved before.

As soon as we imported the script, we are ready to run it.

Run the script#

We first need to double-click on Module1 in the project explorer. Our script appears in the VBA editor window. Then, we press the green triangle icon (Run Sub..) in the taskbar to run the script. Alternatively, we select Run in the context menu and select the Run Sub entry.

We see the output in a window below the VBA editor. We can now close the VBA window and review the changes done in our presentation.

Saving the modified presentation#

Note that when saving the modified presentation, MS PowerPoint will give a warning that scripts cannot be saved in .pptx format. This means that after re-opening the saved file, the script will no longer be available. As we saved the script externally, and can re-load it anytime, this is fine for us. If you want to keep the script saved with the presentation, you can save the presentation as a .pptm file (MS PowerPoint presentation with macros).