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



## bbrimberry (Dec 30, 2022)

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



```
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
```


----------



## Domenic (Dec 31, 2022)

To add a Title Slide, simply use the Add method of the Slides object . . .


```
newPres.Slides.Add 1, ppLayoutTitle
```

Hope this helps!


----------

