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: 21

Excel Facts

Why are there 1,048,576 rows in Excel?
The Excel team increased the size of the grid in 2007. There are 2^20 rows and 2^14 columns for a total of 17 billion cells.

Forum statistics

Threads
1,223,228
Messages
6,170,871
Members
452,363
Latest member
merico17

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