0
votes

I have a code which extract data from Excel and insert it into multiple slides in the PowerPoint.

Dim I As Integer
Dim oXL As Object 'Excel.Aplication
Dim OWB As Object 'Excel.workbook
Dim oSId As Slide
Dim A As Integer
Dim B As Integer
Set oXL = CreateObject(“Excel.Application”)
Set OWB = oXL.Workbooks.Open(FileName:="FileName.xlsx")
A = InputBox(“Page From")
B = InputBox(“Page To")

For I = A To B

oSId.Shapes(“Title l").TextFrame.TextRange.Text = OWB.Sheets(“Sheet1").Range(“A" &
CStr(l)). Value
oSId.Shapes(“Subtitle 2").TextFrame.TextRange.Text = OWB.Sheets(“Sheet1").Range(“B" &
CStr(l)). Value
oSId.Shapes(“Text Placeholder 3").TextFrame.TextRange.Text = OWB.Sheets(“Sheet1").Range(“C" & CStr(l)).Value
oSId.Shapes(“Text Placeholder 4").TextFrame.TextRange.Text = OWB.Sheets(“Sheet1").Range(“D" & CStr(l)).Value

Next
OWB.CIose
oXL.Quit
Set OWB = Nothing
Set oXL = Nothing

End Sub

I want the code to insert picture automatically into PowerPoint based on the cell value of Excel.

For example:

In the PowerPoint Slide, Range A1 is "Apple", Range A2 is "Orange", Range A3 is "Pear"

I have a Folder D:\Users\User\Desktop\Picture\ containing picture of "Apple.jpg", "Orange.jpg", "Pear.jpg".

The code will insert the picture in folder to the slides.

Appreciate your help and guidance! Thank you.

1

1 Answers

0
votes

If I understand you correctly you have pictures name in excel Range("A1"). So you may need the code like e.g. below:

oSId.Shapes.AddPicture( _
   FileName:="D:\Users\User\Desktop\Picture\" & OWB.Sheets(“Sheet1").Range(“A" & CStr(l)).Value & " .jpg", _
   LinkToFile:=msoFalse, _
   SaveWithDocument:=msoTrue, Left:=50, Top:=30, Width:=100, Height:=50).Select