title: How to add pictures to Powerpoint Presentation Picture PlaceHolder?
body: <p>I have created some code in Excel VBA to create a PowerPoint presentation 1 slide for each row of Excel, and populate in a specific text box in PowerPoint.<br>
  I now want to add in all the images that match the description. These are all Jpegs and not charts etc.<br>
  How can I do this, and is it better to do this in excel, or is it better to do this Powerpoint VBA itself?<br>
  Eitherway, would anyone be able to help me out with some code on how to do this please?<br>
  The image frames already exist in PowerPoint. There are 2 images per slide (no transitions or anything).<br>
  Thank you!</p>
  
  <p>P.S I am using PowerPoint and Excel 2010 on Windows 7.</p>
  
  <hr>
  
  <p>Is there a way to do this from Excel? The rest of my code is in Excel and It would be great to do that as part of the Macro.<br>
  Basically I have a file location that I want to use e.g. C:\insertfoldername\imagename.jpeg appears in column H in the spreadsheet (about 400 rows).<br>
  The Powepoint template I am using has the image frame (The one in Powerpoint, that wehn you hover over it says.."Insert Picture from file".<br>
  These are already sized and are in the right location.<br>
  What I want to do is, in Excel, Paste the image from the file path that is in excel and past it into that specific Image frame.<br>
  Is that going to be possible at all?<br></p>
  
  <p>Basically something that will do this:<br>
  <code>PPT.ActivePresentation.Slides(2).Shapes(3)LoadImage(spath)</code></p>
  
  <p>Below is the code I am using.<br>
  **** Indicates the File path. the jpg file is set as the 3rd column in the excel spreadsheet.<br></p>
  
  <pre><code>Sub CreateSlides()
  'Dim the Excel objects
  Dim objWorkbook As New Excel.Workbook
  Dim objWorksheet As Excel.Worksheet
  
  'Dim the File Path String
  Dim strFilePath As String
  
  'Dim the PowerPoint objects
  Dim PPT As Object
  Dim pptSlide As PowerPoint.Slide
  Dim pptLayout As PowerPoint.CustomLayout
  Dim pptNewSlide As PowerPoint.Slide
  Dim str As String
  Dim Title As String
  
  Set PPT = GetObject(, "PowerPoint.Application")
  
  PPT.Visible = True
  
  'Get the layout of the first slide and set a CustomLayout object
  Set pptLayout = PPT.ActivePresentation.Slides(1).CustomLayout
  
  'Run the OpenFile function to get an Open File dialog box. It returns a String containing the file and path.
  strFilePath = OpenFile()
  
  'Open the Excel file
  Set objWorkbook = Excel.Application.Workbooks.Open(strFilePath)
  
  'Grab the first Worksheet in the Workbook
  Set objWorksheet = objWorkbook.Worksheets(1)
  
  'Loop through each used row in Column A
  For i = 2 To objWorksheet.Range("A65536").End(xlUp).Row
  
  Set PPT = GetObject(, "PowerPoint.Application")
  
  Set pptNewSlide = PPT.ActivePresentation.Slides.AddSlide(PPT.ActivePresentation.Slides.Count + 1, pptLayout)
  
   'Get the number of columns in use on the current row
      Dim LastCol As Long
      Dim boldWords As String
  
      boldWords = "Line1: ,line2: ,Line3: ,Line4: "
      LastCol = objWorksheet.Rows(i).End(xlToRight).Column
      If LastCol = 16384 Then LastCol = 1 'For some reason if only column 1 has data it returns 16384, so correct it
  
      'Build a string of all the columns on the row
      str = ""
      str = "Line1: " &amp; str &amp; objWorksheet.Cells(i, 1).Value &amp; Chr(13) &amp; _
      "Line2: " &amp; objWorksheet.Cells(i, 2).Value &amp; Chr(13) &amp; _
      "Line3: " &amp; objWorksheet.Cells(i, 10).Value &amp; Chr(13) &amp; _
      "Line4: " &amp; objWorksheet.Cells(i, 7).Value &amp; Chr(13) &amp; Chr(13) &amp; _
      objWorksheet.Cells(i, 14).Value
  
   sfile = Cells(i, 3) &amp; ".jpg" **** This is the jpg name
  
  Set PPT = GetObject(, "PowerPoint.Application")
  
  spath = "C:\test\"
  
  'Write the string to the slide
  pptNewSlide.Shapes(2).TextFrame.TextRange.Text = objWorksheet.Cells(i, 3).Value 'This enters the film Title
  PPT.ActivePresentation.Slides(PPT.ActivePresentation.Slides.Count).Shapes(1).TextFrame.TextRange.Text = str
  
  
  BoldSomeWords PPT.ActivePresentation.Slides(PPT.ActivePresentation.Slides.Count).Shapes(1), str, boldWords
  
  'This is where I want to load in the Image.
  'PPT.ActivePresentation.Slides(PPT.ActivePresentation.Slides.Count).Shapes(3).Picture = LoadPicture(spath) ' &amp; sfile)
  'PPT.ActivePresentation.Slides(2).Shapes(3)LoadImage((spath))
  
  Next
  End Sub
  </code></pre>
  
  <hr>
  
  <pre><code>Function OpenFile()
  'Dim the File Dialog object and string
  Dim objFileDialog As FileDialog
  Dim strFile As String
  
  'Set the objFileDialog to an instance of the FileDialog object
  Set objFileDialog = Application.FileDialog(msoFileDialogFilePicker)
  
  'Set the Properties of the objFileDialog object
  objFileDialog.AllowMultiSelect = False
  objFileDialog.ButtonName = "Select"
  objFileDialog.InitialView = msoFileDialogViewDetails
  objFileDialog.Title = "Select Excel File"
  objFileDialog.InitialFileName = "C:\"
  objFileDialog.Filters.Clear
  objFileDialog.Filters.Add "Excel", "*.xls; *.xlsx", 1
  objFileDialog.FilterIndex = 1
  
  'Show the FileDialog box
  objFileDialog.Show
  
  'Set strFile to the first record of the SelectedItems property of our FileDialog
  strFile = objFileDialog.SelectedItems(1)
  
  'Return the File Path string
  OpenFile = strFile
  End Function
  </code></pre>