VBA Open a ppt file from excel, loop through the presentation, and make separate presentations based on textbox value

bbrimberry

New Member
Joined
Mar 23, 2016
Messages
34
Hello best VBAers around.


I have a ppt presentation I am opening from excel.

I have a Customer textbox on each slide.

I'd like to make a new presentation when the customer changes.

Any help would be greatly appreciated


VBA Code:
Sub differentpptfiles()


Dim pptApp As PowerPoint.Application
Set pptApp = New PowerPoint.Application

Dim pptPres As PowerPoint.Presentation
Set pptPres = pptApp.Presentations.Open("myfile.pptx")

Dim slide As PowerPoint.slide
Dim currentValue As String

For Each slide In pptPres.Slides
' Check the value of the text box
Dim textBoxValue As String
textBoxValue = slide.Shapes("Customer").TextFrame.TextRange.Text

' If the value of the text box has changed, create a new presentation
If textBoxValue <> currentValue Then
    ' Create a new PowerPoint presentation
    Dim newPres As PowerPoint.Presentation
    Set newPres = pptApp.Presentations.Add

    ' Add the slide to the new presentation
   ' newPres.Slides.AddSlide 1, ppLayoutTitle
' not sure what should go here




    ' Save the new presentation with a unique name
    newPres.SaveAs "C:\Users\name\Desktop\PowerPoint Loop\My Presentation " & currentValue & ".pptx"

    ' Close the new presentation
    newPres.Close

    ' Update the current value of the text box
    currentValue = textBoxValue
End If
Next slide



End Sub
 

Excel Facts

Will the fill handle fill 1, 2, 3?
Yes! Type 1 in a cell. Hold down Ctrl while you drag the fill handle.
To add a Title Slide, simply use the Add method of the Slides object . . .

VBA Code:
newPres.Slides.Add 1, ppLayoutTitle

Hope this helps!
 
Upvote 0

Forum statistics

Threads
1,224,814
Messages
6,181,128
Members
453,021
Latest member
Justyna P

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