Create Powerpoint slides with pictures from Excel database

palmers40

New Member
Joined
Jan 12, 2020
Messages
2
Office Version
  1. 2016
Platform
  1. Windows
Hello

I would like to create individual Powerpoint slides from a Excel database and also include a picture. The data is standard with Name, Story, Picture filename.
The Powerpoint template will be the same for each slide with the Name as the title, the picture on the left and the Story on the right.

I have 900 rows of data so any help to enable me to create the slides using VBA would be grateful.

Thank You
 

Attachments

  • PPT data.JPG
    PPT data.JPG
    64.7 KB · Views: 67

Excel Facts

Format cells as currency
Select range and press Ctrl+Shift+4 to format cells as currency. (Shift 4 is the $ sign).
NOTE - you must add reference to the Microsoft PowerPoint Object Library - in VBA edtor Click on Tools \ References\ scroll down and select the correct box \ click OK

PowerPointObjectLibrary.jpg



Try this on a copy of your data

Amend name of the sheet if your data is not in sheet named "Sheet1"
Set ws = Sheets("Sheet1")

I suggest you test with about 10 rows of data initially
After initial test amend the code to place the various objects where required and to format each text box as desired etc

The code below should be placed in a NEW module in your workbook
VBA Code:
Option Explicit
    Dim pp As PowerPoint.Application, ppPres As PowerPoint.Presentation, ppSlide As PowerPoint.Slide, ppShape As PowerPoint.Shape

Sub NewPresentation()
'worksheet range
    Dim ws As Worksheet, Cel As Range
    Set ws = Sheets("Sheet1")
'create presentation
    Set pp = New PowerPoint.Application
    Set ppPres = pp.Presentations.Add
    pp.Visible = True 'msoTrue
'add slides
    For Each Cel In ws.Range("A2", ws.Range("A" & Rows.Count).End(xlUp))
        Call AddASlide(Cel, Cel.Offset(, 1), Cel.Offset(, 2))
    Next
End Sub

Private Sub AddASlide(Person As Range, Story As Range, PathToPic As Range)
    On Error Resume Next
'create the slide
    ppPres.Slides.Add ppPres.Slides.Count + 1, ppLayoutBlank
    Set ppSlide = ppPres.Slides(ppPres.Slides.Count)
'add namebox & text
    Set ppShape = ppSlide.Shapes.AddTextbox(msoTextOrientationHorizontal, Left:=100, Top:=50, Width:=200, Height:=50)
    ppShape.TextFrame.TextRange.Text = Person
    ppShape.TextFrame.TextRange.Font.Size = 30
    ppShape.TextFrame.TextRange.Font.Bold = True
'add storybox & text
    Set ppShape = ppSlide.Shapes.AddTextbox(msoTextOrientationHorizontal, Left:=600, Top:=100, Width:=200, Height:=50)
    ppShape.TextFrame.TextRange.Text = Story
'insert picture
    ppSlide.Shapes.AddPicture Filename:=PathToPic, LinkToFile:=msoFalse, SaveWithDocument:=msoTrue, Left:=100, Top:=150, Width:=200, Height:=300
End Sub



NOTE

Above was tested with data set out EXACTLY as per picture in post#1 and it worked without any issues
If for any reason your initial 10 row test fails to run (or misbehaves) then post the data used in support of any questions you may have
 
Last edited:
Upvote 0
just spotted a little gremlin which is doing no damage but 'msoTrue should be removed in this line

pp.Visible = True 'msoTrue
 
Upvote 0
You may prefer that the image aspect ratio does not change when resized
Code below makes the height 300
Maximum image width set to 450 (height reduced to match)
VBA Code:
'picture
    ppSlide.Shapes.AddPicture Filename:=PathToPic, LinkToFile:=msoFalse, SaveWithDocument:=msoTrue, Left:=100, Top:=150
    With ppSlide.Shapes(ppSlide.Shapes.Count)
        .LockAspectRatio = msoTrue
        .Height = 300
        If .Width > 450 Then .Width = 450
    End With
 
Upvote 0
Thank you so much Yongle, works a treat.

I know enough to be able to resize the text boxes now as well.

Cheers
 
Upvote 0

Forum statistics

Threads
1,222,871
Messages
6,168,745
Members
452,214
Latest member
mittals888

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