Resizing Image in Power Point VBA

I have this code that works really well in excel...I wanted the existing code to actually paste it with height and width of the image so that it fits on my slide.  It currently pastes the image big and I have to go into each slide and resize all of them.  Atleast resize it within the slide parameters...

Here is the code.

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")
   
        Err.Clear

      If PowerPointApp Is Nothing Then
        MsgBox "PowerPoint Presentation is not open, aborting."
        Exit Sub
      End If
   
       If Err.Number = 429 Then
        MsgBox "PowerPoint could not be found, aborting."
        Exit Sub
      End If

  On Error GoTo 0
 
  PowerPointApp.ActiveWindow.Panes(2).Activate
   
  Set myPresentation = PowerPointApp.ActivePresentation
 
  MySlideArray = Array(2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20)

    MyRangeArray = Array(Sheet12.Range("A1:F50"), Sheet1.Range("A1:K17"), _
      Sheet13.Range("A1:G50"), Sheet15.Range("A1:K17"), _
      Sheet14.Range("A1:H30"), Sheet16.Range("A1:K17"), _
      Sheet20.Range("A1:I30"), Sheet17.Range("A1:K17"), _
      Sheet21.Range("A1:I50"), Sheet18.Range("A1:K17"), _
      Sheet22.Range("A1:F50"), Sheet19.Range("A1:K17"), _
      Sheet2.Range("A1:E50"), Sheet23.Range("A1:K17"), _
      Sheet5.Range("A1:H17"))

  For x = LBound(MySlideArray) To UBound(MySlideArray)
           MyRangeArray(x).Copy
   
       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
   
      With myPresentation.PageSetup
        shp.Left = (.SlideWidth \ 2) - (shp.Width \ 2)
        shp.Top = (.SlideHeight \ 2) - (shp.Height \ 2)
      End With
     
  Next x

   Application.CutCopyMode = False
  ThisWorkbook.Activate
  MsgBox "Complete!"

End Sub
LUIS FREUNDAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Jamie GarrochPowerPoint Consultant & DeveloperCommented:
Change this bit:

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

Open in new window


to this:

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

Open in new window

0
LUIS FREUNDAuthor Commented:
Close.....it still does the same on some slides.  Others are still big.....
0
Jamie GarrochPowerPoint Consultant & DeveloperCommented:
I'm not sure why this line is there since the previous line is setting a reference to the posted shape. What happens if you comment it out?

Set shp = PowerPointApp.ActiveWindow.Selection.ShapeRange 'Excel 2013

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Office

From novice to tech pro — start learning today.