We would like to be able to record a macro that inserts another slide and adds the title for that new slide.
It is always worth rehearsing the steps before you use the Macro Recorder. If you make any unnecessary steps it will create more code than is actually needed.
Lets rehearse the steps first. Select (Insert > New Slide). The Task Pane should be opened on the right hand side.
A new "Title and Text" slide should be inserted (since this is the default).
The task pane may also appear on the right hand side. You can check your options (Tools > Options)(View tab, "Slide Layout task pane when inserting new slides").
The task pane is only displayed so you can easily change the type of slide layout if you do not want a "Title and Text" slide.
Select the title placeholder and enter the title "BetterSolutions.com".

alt text

You are now ready to record the actual macro, so lets start by deleting this slide

Record the Macro

Select (Tools > Macro > Record New Macro) to display the Record Macro dialog box. Give the macro the name "InsertingSlide".
You don't have to worry about changing the "Store macro in" drop-down list as recorded macros are always placed in the active presentation.
Press OK to start recording. The Stop recording toolbar should be displayed.

alt text

Select (Insert > New Slide).
Find the slide layout "Title and Text" and display the drop-down menu and select "Insert New Slide".
Select the title placeholder and enter the title "Another Slide".
Press the stop recording button on the Stop Recording toolbar.
The toolbar will then disappear.

Locating the Macro

Once you have recorded the macro viewing the code is very easy. This is done in the Visual Basic Editor.
You can edit a macro by selecting (Tools > Macro > Macros). Select the name of the macro and press the "Edit" button. This will open the Visual Basic Editor in another window.
Using this method will locate the macro for you and will display the code module where the macro can be found.

alt text

Another application window should open and you should see the following lines of code.

Editing the Code

Notice that the default description is placed as a comment at the top of the macro.

Sub InsertingSlide() 
' Macro recorded #date# by Russell Proctor

   ActiveWindow.View.GotoSlide Index:=ActivePresentation.Slides.Add(Index:=2, Layout:=ppLayoutText).SlideIndex
   ActiveWindow.Selection.SlideRange.Shapes("Rectangle 2").Select
   ActiveWindow.Selection.ShapeRange.TextFrame.TextRange.Characters(Start:=1, Length:=0).Select
   With ActiveWindow.Selection.TextRange
      .Text = "Another Slide"
      With .Font
         .Name = "Arial"
         .Size = 44
         .Bold = msoFalse
         .Italic = msoFalse
         .Underline = msoFalse
         .Shadow = msoFalse
         .Emboss = msoFalse
         .BaselineOffset = 0
         .AutoRotateNumbers = msoFalse
         .Color.SchemeColor = ppTitle
      End With
   End With
End Sub

Select this slide and run this macro. A new slide will be inserted with the same title.
The Macro Recorder will always include some line lines of code that can be removed.
The above macro could be simplified significantly and the result would be exactly the same.

Writing Efficient Code

The first thing to remove is the comments. These are the lines that start with a " ' " and are displayed in green in the Visual Basic Editor.
The following macro performs exactly the same action as the macro that was recorded, although this macro is significantly more efficient and will therefore run a lot faster.
This macro has the slideindex hard typed to "2" so any new slides which you insert using this macro will be inserted as slide number 2.

Sub InsertingSlide() 
   ActiveWindow.View.GotoSlide Index:=ActivePresentation.Slides.Add(Index:=2, Layout:=ppLayoutText).SlideIndex
   ActiveWindow.Selection.SlideRange.Shapes("Rectangle 2").Select
   ActiveWindow.Selection.SlideRange.Shapes("Rectangle 2").TextFrame.TextRange.Text = "Another Slide"
End Sub

For small macros speed is not that important. Both the above macros will only take a split second to run so you will probably not even notice a difference.
For larger, more complicated macros, speed becomes more of an issue. It is very easy to write a macro that works, but it requires a lot of practice to write a macro that is efficient.
You could have typed the above code directly into the code window if you were familiar with VBA code.
Being able to write macros directly into the code window will take some practice but the Macro Recorder is the best place to start if you want to learn more about the code.


It is also important to remember that you do not need to select the cells, sheet, object, etc in order to be able to manipulate or format it. This can save a lot of time.
You can press (Tools > Macro > Visual Basic Editor) at any time to open the Visual Basic Editor directly.
There is no Application.ScreenUpdating property in PowerPoint (unlike Excel and Word).

© 2023 Better Solutions Limited. All Rights Reserved. © 2023 Better Solutions Limited TopPrevNext