How do I use excel VBA to insert blank slide every 5th slide

BuJay

Board Regular
Joined
Jun 24, 2020
Messages
73
Office Version
  1. 365
  2. 2019
  3. 2016
  4. 2013
Platform
  1. Windows
Suppose I have 50 slides in a powerpoint.

I can create a macro that opens it....

How would I insert a new blank slide in front of first slide, and then a new blank slide after every 5 slides...

So end product would have 61 slides....as follows:

New1, Old1, Old2, Old3, Old4, Old5, New2, Old6, Old7, Old8, Old9, Old10, New3, .....etc.
 

Attachments

  • 1674690975835.png
    1674690975835.png
    7.7 KB · Views: 4

Excel Facts

Square and cube roots
The =SQRT(25) is a square root. For a cube root, use =125^(1/3). For a fourth root, use =625^(1/4).
Hey, try this code:

Just remember to enable PowerPoint reference. :)

VBA Code:
Sub PowerPointAddSlides()

Dim DestinationPPT As String
Dim counting As Double
Dim PowerPointApp As PowerPoint.Application
Dim myPresentation As PowerPoint.Presentation
Dim pptLayout As CustomLayout

Set PowerPointApp = CreateObject("PowerPoint.Application")

DestinationPPT = "path" 'change to your path
Set myPresentation = PowerPointApp.Presentations.Open(DestinationPPT)

For i = 1 To 55 Step 5

Set pptLayout = myPresentation.Slides(1).CustomLayout
myPresentation.Slides.AddSlide (i + counting), pptLayout
counting = counting + 1

Next i

End Sub
 
Upvote 0
Hey, try this code:

Just remember to enable PowerPoint reference. :)

VBA Code:
Sub PowerPointAddSlides()

Dim DestinationPPT As String
Dim counting As Double
Dim PowerPointApp As PowerPoint.Application
Dim myPresentation As PowerPoint.Presentation
Dim pptLayout As CustomLayout

Set PowerPointApp = CreateObject("PowerPoint.Application")

DestinationPPT = "path" 'change to your path
Set myPresentation = PowerPointApp.Presentations.Open(DestinationPPT)

For i = 1 To 55 Step 5

Set pptLayout = myPresentation.Slides(1).CustomLayout
myPresentation.Slides.AddSlide (i + counting), pptLayout
counting = counting + 1

Next i

End Sub
Looks great. For some reason, it is inserting a slide with a Click to add title box and a Click to add subtitle box. Is there a way to prevent the subtitle box from appearing? I can actually use the Title box!
 
Upvote 0
or better yet, maybe keep the subtitle box but add a date in this form? As of December 31, 2022 with the date coded into the vba as a macro variable?
 
Upvote 0
Here is the update:

VBA Code:
Sub PowerPointAddSlides()

Dim DestinationPPT As String
Dim counting As Double
Dim PowerPointApp As PowerPoint.Application
Dim myPresentation As PowerPoint.Presentation
Dim pptLayout As CustomLayout
Dim shp As PowerPoint.Shape

Set PowerPointApp = CreateObject("PowerPoint.Application")

DestinationPPT = "path" 'change to your path
Set myPresentation = PowerPointApp.Presentations.Open(DestinationPPT)

For i = 1 To 55 Step 5

Set pptLayout = myPresentation.Slides(1).CustomLayout
myPresentation.Slides.AddSlide (i + counting), pptLayout

For Each shp In myPresentation.Slides(i + counting).Shapes
If InStr(1, shp.Name, "Subtitle") Then shp.TextFrame.TextRange.Text = "December 31, 2022" 'your custom text
Next shp

counting = counting + 1

Next i

End Sub
 
Upvote 0
Solution
Here is the update:

VBA Code:
Sub PowerPointAddSlides()

Dim DestinationPPT As String
Dim counting As Double
Dim PowerPointApp As PowerPoint.Application
Dim myPresentation As PowerPoint.Presentation
Dim pptLayout As CustomLayout
Dim shp As PowerPoint.Shape

Set PowerPointApp = CreateObject("PowerPoint.Application")

DestinationPPT = "path" 'change to your path
Set myPresentation = PowerPointApp.Presentations.Open(DestinationPPT)

For i = 1 To 55 Step 5

Set pptLayout = myPresentation.Slides(1).CustomLayout
myPresentation.Slides.AddSlide (i + counting), pptLayout

For Each shp In myPresentation.Slides(i + counting).Shapes
If InStr(1, shp.Name, "Subtitle") Then shp.TextFrame.TextRange.Text = "December 31, 2022" 'your custom text
Next shp

counting = counting + 1

Next i

End Sub
Awesome! Thank you!
 
Upvote 0

Forum statistics

Threads
1,215,069
Messages
6,122,959
Members
449,096
Latest member
Anshu121

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top