LUIS FREUND
asked on
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:="PowerPoi nt.Applica tion")
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.ActivePresen tation
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:F5 0"), 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(MySl ideArray(x )).Shapes. PasteSpeci al(DataTyp e:=2) 'Excel 2007-2010
Set shp = PowerPointApp.ActiveWindow .Selection .ShapeRang e '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
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:="PowerPoi
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
Set myPresentation = PowerPointApp.ActivePresen
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:F5
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(MySl
Set shp = PowerPointApp.ActiveWindow
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
ASKER
Close.....it still does the same on some slides. Others are still big.....
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Open in new window
to this:
Open in new window