+5 votes
488 views
in Sell ​​on the Internet by (242k points)
reopened
PowerPoint macros: automate your daily use of PowerPoint

1 Answer

+3 votes
by (1.6m points)
edited
 
Best answer

What is a PowerPoint macro?
How does a PowerPoint macro work?
Create and open macros in PowerPoint
How to link PowerPoint macros with a button or key combination
PowerPoint Macros: Useful VBA Code Examples
Step 1: open the Visual Basic editor
Step 2: create the first macro in PowerPoint
Step 3: save the PowerPoint macro you created
Step 4: run the PowerPoint macro created through the macro menu
Add the button? Macros? to the toolbar for quick access
Add the button? Macros? to a tab's ribbon

image

PowerPoint macros: automate your daily use of PowerPoint

PowerPoint has been one of the preferred solutions for creating digital presentations for decades . It is estimated that more than 100 billion slides are created each year with Microsoft software, for example to accompany school exhibits, public lectures, or business presentations with images and text. And those who use the software (available to all Microsoft Office Suite users ) can make their job easier with just a few clicks. The templates , for example, are very popular because they contain some designs or predefined formats, such as fonts, font sizes or options of color ready for use..

When certain tasks and actions are repeated frequently , it pays to speed them up using macros in PowerPoint. As in Excel, macros allow you to record sequences and combinations of keyboard inputs and mouse clicks in your presentation software to keep them ready and accessible. We explain how to create a macro with PowerPoint and integrate it into projects.

Index
  1. What is a PowerPoint macro?
  2. How does a PowerPoint macro work?
  3. Create and open macros in PowerPoint
    1. Step 1: open the Visual Basic editor
    2. Step 2: create the first macro in PowerPoint
    3. Step 3: save the PowerPoint macro you created
    4. Step 4: run the PowerPoint macro created through the macro menu
  4. How to link PowerPoint macros with a button or key combination
    1. Add the button? Macros? to the toolbar for quick access
    2. Add the button? Macros? to a tab's ribbon
  5. PowerPoint Macros: Useful VBA Code Examples

What is a PowerPoint macro?

Microsoft Office Suite programs generally offer the ability to create (or implement) macros and run them. Besides creating macros in PowerPoint, you can also create them in Word, Excel or Access. These macros, functioning as a kind of applet in the application, always serve the same purpose: they describe a sequence of commands and actions that is automatically executed in the order specified when activated. It can be both keystrokes (individual keys or combinations thereof) and mouse clicks ..

With the use of a macro in PowerPoint, you save yourself having to perform all the steps that are stored in it. This is an advantage, especially when they are repeated often .

How does a PowerPoint macro work?

In order to fulfill their function later, macros describe the saved instructions as code. PowerPoint processes that code automatically when the macro is started to run the corresponding script. To do this, all the macros in PowerPoint and other Microsoft Office programs use a programming language called VBA (Visual Basic for Applications). This language is derived from the BASIC dialect that Microsoft developed and implemented as a universal macro language in the mid-1990s for its Office tools. To create macros in PowerPoint, it is essential to master this scripting language. With the Visual Basic Editor, the Office tools incorporate a practical own development environment for this..

To start or run a macro in PowerPoint, you have three options:

  • Start it from the Macros menu .
  • Start it in the quick access menu .
  • Launch it on the ribbon for a random tab.
Note

Other programs in the Microsoft Office Suite, such as Word or Excel, include a macro recorder for recording scripts. The underlying VBA code is thus generated automatically so that you can create new macros without having to know the scripting language. However, this recording feature is no longer available in PowerPoint as of version 2010.

Create and open macros in PowerPoint

If you want to create macros with current editions of PowerPoint , the only way to do it is with Visual Basic for Applications. Before you read in the following step-by-step instructions how to create your own automatisms with the integrated editor, you will have to delve into the syntax and possibilities of this programming language . You will find a good basis for this in the following Visual Basic Applications tutorial.

Step 1: open the Visual Basic editor

You can write the VBA codes with any code editor you want. In any case, the Visual Basic editor, which is integrated into PowerPoint, is recommended as a convenient and simple solution for integrating macros. Since the editor is included among the? Developer tools? Microsoft Office Suite, which are normally deactivated, you will first have to activate it. To do this, go to the tab? File ?, and there you access the? Options ?. Open the menu here? Customize Ribbon ?, with which you can customize the application toolbar.

Right-click on the entry? Main tabs ?, put the check symbol to? Programmer ? or? Developer ?, depending on the version, and then click? Accept ? To add the tab corresponding to your PowerPoint installation:

image
If you have added the developer tools to your PowerPoint tabs, you can remove the tab at any time by accessing Options and unchecking the given box.

Now, in the ribbon, you will also see the "Developer" tab. Once in it, you can open the VBA editor at any time with the button on the bar? Visual Basic ?

image
If you want to import other macros into PowerPoint, the only way to do it is also with the software's own Visual Basic editor.

Step 2: create the first macro in PowerPoint

The easiest way to create a new macro in PowerPoint with the VBA editor is with the button? Macros ? which is right next to the "Visual Basic" button. Clicking this button brings up a menu where you can enter whatever name you want for the macro. After, under? Macro in ?, Selects in which PowerPoint document the command string to be created should be available. If you choose the option? All open presentations ?, the macro can be used in all projects . To finish, click the button? Create ?:

image
If you want to create and use macros in PowerPoint with notifications, you first have to activate these types of macros in? Macro security ?.

PowerPoint starts the Visual Basic editor automatically, as well as the default code window. There you will also see the start line and the end line of your macro's VBA code . As in the previous step we have chosen the name? Test? for our macro, these two lines turn out like this:

  Sub Prueba() End Sub  

Now you can enter the VBA code between the two instructions for the start and end of the PowerPoint macro.

Step 3: save the PowerPoint macro you created

To integrate your macro permanently into your PowerPoint installation, you have the option of saving it in the folder that is currently open or in the one that has been specially created to save the macros. To do this, click on the save symbol on the VBA editor toolbar .

PowerPoint then opens a dialog box where the application warns you that macros can only be saved in documents of the type? PowerPoint template with macro? or? PowerPoint presentation with macro ?. Click? No ? to change the file type of your current document or to indicate the location of the corresponding template:

image
If you save your PowerPoint document as a presentation or template with a macro, it will be given the file extension .pptm or .potm instead of the usual .pptx extension.

Now, in? File type ?, select the option? Macro-enabled PowerPoint presentation ? or? Macro-Enabled PowerPoint Template ?, or the location of your PowerPoint macro template (if you created it previously), before clicking? Save ? in the last step:

image
For PowerPoint templates, Microsoft PowerPoint automatically sets a template directory as the storage location, although you are not required to use it to make use of the templates.

Step 4: run the PowerPoint macro created through the macro menu

As soon as you save the macro to a specific PowerPoint presentation or template, you can run it at any time. The easiest way to do it in this case is also through the macro menu, in the ribbon of the? Developer? Tab: go to the tab and click on the button? Macros ?, just like you did for creating the macro.

image
You can also access the menu to create, run and edit PowerPoint macros using a combination of keys: to do this you just have to press the [Alt], [W] and [0] keys consecutively.

The created and saved macro will now appear in the window, which you can select by clicking the left mouse button. To start the script, just press the button? Run ?, Which causes the menu to close again and the macro code to run.

How to link PowerPoint macros with a button or key combination

Macros should design workflows and processes in PowerPoint as simple as possible, so it is essential that they start quickly and without complications. The option we mentioned earlier, starting a macro through the macro menu, does not fully satisfy this requirement. For this reason, the Microsoft application offers two alternatives with the launch of the macro through a button located in the quick access bar or in the ribbon of any tab to execute the PowerPoint macros in a single step.

Add the button? Macros? to the toolbar for quick access

For a quick launch of a PowerPoint macro, you can add a button to the Quick Access Toolbar or to the Ribbon of any tab. By default, the toolbar already contains some buttons for quick execution of certain steps of the program , for example, saving the current document. If you want to expand this bar with a button for your macro, first access Options (through the? File? Tab). There, go to the category? Quick Access Toolbar ?:

image
In the PowerPoint menu for customizing the Quick Access Bar, you can delete or edit default items such as the Save button and, for example, change the symbol.

In? Select Commands? (left window), select the entry? Macros ? and left or right click on the created macro. Then press the button? Add? for PowerPoint to include the macro in the right menu window:

image
Under? Customize Quick Access Toolbar ?, indicates whether the changes to the toolbar should apply only to the current PowerPoint document or to all.

If you click on the macro entry in the window on the right and then select? Modify ?, you can change the name and symbol of the button. Finally, confirm the new button on the quick access bar with "OK".

image
Modified Quick Access Toolbar in PowerPoint 2016.

Add the button? Macros? to a tab's ribbon

To add a button? Macros? You have to follow practically the same steps to add it to the quick access bar to the ribbon of a given tab. However, an additional step is required. Unlike the Quick Launch bar, the button can only be integrated after a user-defined group has been created .

First you must also access the PowerPoint options (? File?? Options?). Then navigate to the category? Customize Ribbon ? and double-click in the right menu window on the tab in which you want to integrate the Macros button. Then press? New group ? To add this tab to the mentioned user defined group:

image
Groups are used to sort the buttons on the Ribbon of PowerPoint tabs into specific categories.

With ? Change name ? Can you give an informative name to the newly created group before selecting the point? Macros ? in the left menu window, located at? Select commands? . Click on the macro that should have a button on the ribbon and arrange it in the group with the button? Add ?.

image
The hierarchical classification of tabs and groups makes it easier for you to correctly assign PowerPoint macros.

How it happens with the button? Macros? for the quick access bar, at the end you can also assign an individual symbol to your PowerPoint macro by selecting it in the right menu window and clicking? Change name ? Close the Options with? Accept ? and you will find the new button in the group created in the ribbon of the chosen tab:

image
Custom Ribbon for PowerPoint tab? Developer? with an example macro button.

PowerPoint Macros: Useful VBA Code Examples

Visual Basic for Applications allows you to program a multitude of different macros in PowerPoint. On the one hand, it can be executable scripts, which help you precisely in your daily work with presentation software . On the other hand, in this way you can also integrate simple functions in the program that do not have to be necessary for the preparation of your presentations. For example, the following PowerPoint macro is an example for informational purposes only:

  Sub Test() Dim strText As String strText = "Sistema operativo: " & _ Application.OperatingSystem _ & Chr(10) strText = strText & "Directorio: " _ & Application.Path & Chr(10) strText = strText & "Nombre de la aplicación: " _ & Application.Name & Chr(10) strText = strText & "Versión: " & _ Application.Version MsgBox strText, vbInformation, _ "Información del programa" End Sub  

If PowerPoint runs this VBA code, various information is accessed : the name of the operating system on which PowerPoint is running, sample information about the directory in which the application is saved, as well as the name and version number of the PowerPoint installation. The Microsoft application then displays the results of the check in a message box called? Program Information ?:

image
The macro code that is displayed determines the directory in PowerPoint that you look in by the location of the presentation program's startup file.

This one that follows is another example of a macro that will greatly facilitate your work with the Microsoft program. The following sizable VBA code extends your presentation software with a macro that automatically creates an index for selected slides , with or without hyperlinks, as you decide:

  Option Explicit Sub Agenda(Optional Hyperlinks As Boolean) Dim i As Integer Dim o As Integer Dim strSel As String Dim strTítulo As String Dim strTítuloAgenda As String Dim slAgenda As Slide Dim intPos As Integer Dim OrdenDiapositivas() As Integer On Error Resume Next If ActiveWindow.Selection.SlideRange.Count > 0 Then ReDim OrdenDiapositivas(1 To ActiveWindow.Selection.SlideRange.Count) 'Seleccionar la posición de la diapositiva de contenido intPos = InputBox("¿Antes de qué diapositiva debe introducirse la agenda?", "Posición de la agenda") 'Cancelar si el valor es mayor que el número de diapositivas If intPos > ActivePresentation.Slides.Count Then MsgBox "El valor seleccionado es mayor que el número de diapositivas de la presentación." Exit Sub End If 'Introducir título de la diapositiva de índice strAgendaTitel = InputBox("¿Qué título debe tener la diapositiva índice?", "Introducir título") 'Determinar los ID de las diapositivas seleccionadas For i = 1 To ActiveWindow.Selection.SlideRange.Count FolienFolge(i) = ActiveWindow.Selection.SlideRange(i).SlideIndex Next For o = 1 To UBound(OrdenDiapositivas) If ActivePresentation.Slides(OrdenDiapositivas(o)).Shapes.HasTitle Then 'Build up the ToC Text strTitel = ActivePresentation.Slides(OrdenDiapositivas(o)).Shapes.Title.TextFrame.TextRange.Text strSel = strSel & strTitel & vbCrLf End If Next 'Insertar la diapositiva vacía en la posición deseada, introducir el título y los encabezados Set slAgenda = ActivePresentation.Slides.Add(intPos, ppLayoutText) slAgenda.Shapes(1).TextFrame.TextRange = strAgendaTitel slAgenda.Shapes(2).TextFrame.TextRange = strSel 'Insertar hipervínculos If Hyperlinks Then For o = 1 To UBound(OrdenDiapositivas) If ActivePresentation.Slides(OrdenDiapositivas (o) + 1).Shapes.HasTitle Then 'Build up the ToC Text strTitel = ActivePresentation.Slides(OrdenDiapositiva(o) + 1).Shapes.Title.TextFrame.TextRange.Text With slAgenda.Shapes(2).TextFrame.TextRange.Paragraphs(o).ActionSettings(ppMouseClick) .Action = ppActionHyperlink .Hyperlink.Address = "" .Hyperlink.SubAddress = ActivePresentation.Slides(OrdenDiapositivas(o) + 1).SlideID & "," & ActivePresentation.Slides(OrdenDiapositivas(o) + 1).SlideIndex & "," + strTitel End With End If Next End If End If End Sub Sub DirectorioSinHipervínculos() 'Insertar directorio sin hipervínculos Agenda (False) End Sub Sub DirectorioConHipervínculos() 'Insertar directorio con hipervínculos Agenda (True) End Sub  

To take advantage of the possibilities offered by this macro, which is saved in the PowerPoint installation in the two variants? Directory without hyperlinks? and? Directory with hyperlinks ?, only the slides that you want to represent in the index are selected. This requires that all the desired slides are selected when starting the PowerPoint macro. This is accomplished by holding down the [Ctrl] key and left-clicking on the relevant series of slides. The order you maintain in doing so has a decisive influence on the index: the macro presents each index entry in exactly the reverse order of the selection you make.

Now, after starting the macro, you have to answer two questions:

  1. BEFORE which slide should the agenda be introduced?
  2. What title should the index slide have?
image
PowerPoint highlights selected slides with a colored border (in this case, orange).

When you provide the two information and confirm "OK", the PowerPoint macro creates a slide with the index in the desired place. If selected, it will include hyperlinks to the different slides:

image
The title and the position of the automatically created index can be easily changed later by editing the line or moving the slide to the list.

Please, take into account the legal notice related to this article.


...