How can i make power point slides based on Excel Range A2:B2. All the characters(countryname) for excel rowA1 to A10 make it as a Power Point Slide.

Here is my Code in excel macro but i am getting an error for array..

 Sub PasteMultipleSlides()
 Dim myPresentation As Object
 Dim mySlide As Object
 Dim PowerPointApp As Object
 Dim shp As Object
 Dim MySlideArray As Variant
 Dim MyRangeArray As Variant
 Dim x As Long

 On Error Resume Next

 Set PowerPointApp = GetObject(class:="PowerPoint.Application")

'Clear the error between errors

 'If PowerPoint is not already open then Exit
  If PowerPointApp Is Nothing Then
   MsgBox "PowerPoint Presentation is not open, aborting."
    Exit Sub
    End If

   'Handle if the PowerPoint Application is not found
    If Err.Number = 429 Then
     MsgBox "PowerPoint could not be found, aborting."
     Exit Sub
      End If

       On Error GoTo 0

       'Make PowerPoint Visible and Active

         'Create a New Presentation
         Set myPresentation = PowerPointApp.ActivePresentation

     'List of PPT Slides to Paste to
      MySlideArray = Array(2, 3, 4, 5, 6)

    'List of Excel Ranges to Copy from
     MyRangeArray = Array(Sheet1.Range("A2:B10"))

     'Loop through Array data
     For x = LBound(MySlideArray) To UBound(MySlideArray)
     'Copy Excel Range

     'Paste to PowerPoint and position
     On Error Resume Next
      Set shp =      myPresentation.Slides(MySlideArray(x)).Shapes.PasteSpecial(DataType:=2) 'Excel 2007-2010
Set shp = PowerPointApp.ActiveWindow.Selection.ShapeRange 'Excel 2013
 On Error GoTo 0

 'Center Object
  With myPresentation.PageSetup
    shp.Left = (.SlideWidth \ 2) - (shp.Width \ 2)
    shp.Top = (.SlideHeight \ 2) - (shp.Height \ 2)
  End With

 Next x

 'Transfer Complete
 Application.CutCopyMode = False
 MsgBox "Complete!"

End Sub
  • 1
    What error message? What line? – dbmitch Aug 5 '16 at 4:32

You might have more than one error but it looks like you should change the way you create your MyRangeArray.

Declare it as unallocated array

Dim MyRangeArray() As Variant

No need to use Array function to convert it via Array()

MyRangeArray = Range("A1:A10")

Now, MyRangeArray is dimensioned automatically as MyRangeArray(1 to 10, 1 To 1)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.