Create Powerpoint slides with pictures from Excel database

bbrimberry

New Member
Joined
Mar 23, 2016
Messages
34
Hello,


the code below works beautifully but how can I adjust it when I have more columns of data?
I assume I need to adjust the offset line?
Say I had a phone number or address?

thanks in advance!



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
 

Attachments

  • vba.PNG
    vba.PNG
    10.2 KB · Views: 17

Excel Facts

Who is Mr Spreadsheet?
Author John Walkenbach was Mr Spreadsheet until his retirement in June 2019.

Forum statistics

Threads
1,214,957
Messages
6,122,472
Members
449,087
Latest member
RExcelSearch

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