Open and modify a powerpoint from a list of excel

Pachino

New Member
Joined
Apr 10, 2018
Messages
2
I have several powerpoint listed in column A, a title and a text in column B and C and the path of a picture in column D. Can I use VBA to open each file from column A and update the second slide with title and text of column B and C and then insert picture of column D to the third slide? Thanks in advance.
Example :
https://m.imgur.com/EwymcQF
 

Excel Facts

Shade all formula cells
To shade all formula cells: Home, Find & Select, Formulas to select all formulas. Then apply a light fill color.
Hello Pachino,

since I never programmed Powerpoint automation from Excel/vba before this was a bit of a challenge. The following code does what you want and has these assumptions:
  • cell B1 contains the path to the folder with the powerpoint and picture files
  • the (only) worksheet is labelled 'Sheet1'
Code:
Option Explicit
Private ppApp As PowerPoint.Application

Sub updatePPfiles()
    Dim ppPath As String, ppList() As Variant
    Dim i As Integer
    'note: ppApp declared outside sub
    Dim ppPresentation  As PowerPoint.Presentation
    Dim ppSlides        As PowerPoint.Slides
    Dim ppSlide         As PowerPoint.Slide
    Dim slideShapes     As PowerPoint.Shapes
    Dim ShapeReference  As PowerPoint.Shape
    Dim ppShape         As PowerPoint.Shape
    Dim sh1 As Worksheet
    
    Set sh1 = ThisWorkbook.Worksheets("Sheet1")
    
    'set powerpoint application object once
    If ppApp Is Nothing Then Set ppApp = New PowerPoint.Application
    
    With sh1
        ppPath = .Range("B1")   'cell B1 holds the path to the folder with powerpoint
        ppList = .Range("A4:D" & .Range("A4").End(xlDown).Row) 'list -> array
    End With
        
    'update slides
    For i = 1 To UBound(ppList, 1)
        Set ppPresentation = ppApp.Presentations.Open( _
            ppPath & ppList(i, 1) & ".pptx", WithWindow:=msoFalse)
        
        Set ppSlides = ppPresentation.Slides
        
        'title and text to 2nd slide
        Set ppSlide = ppSlides(2)
        Set slideShapes = ppSlide.Shapes
        slideShapes(1).TextFrame.TextRange.Text = ppList(i, 2)
        slideShapes(2).TextFrame.TextRange.Text = ppList(i, 3)
        
        'pic to 3rd slide
        Set ppSlide = ppSlides(3)
        Set slideShapes = ppSlide.Shapes
        Set ShapeReference = slideShapes(1) 'picture to anchor to
        With ShapeReference
        Set ppShape = slideShapes.AddPicture(ppPath & ppList(i, 4), msoFalse, msoCTrue, _
        .Left, .Top, .Width, .Height)
        End With
        ShapeReference.Delete
        
        ppPresentation.Save
        ppPresentation.Close
    Next i
End Sub
 
Last edited:
Upvote 0

Forum statistics

Threads
1,223,635
Messages
6,173,481
Members
452,516
Latest member
archcalx

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