Vba – Resizing picture using Powerpoint vba

image resizingpowerpointvba

I am trying to resize a picture that I have pasted into powerpoint from Excel using powerpoint vba.

My code says:

ActivePresentation.Slides(9).Select
Application.ActiveWindow.View.PasteSpecial DataType:=ppPasteEnhancedMetafile

This part works fine, I am at a loss as how to then resize the picture in the next step. I am new to using powerpoint vba.

Any help would be much appreciated.

Best Answer

  • Never select anything unless you absolutely must, and you very rarely must.. Get a reference to the shape instead.

  • You don't actually need to be viewing a slide to manipulate the shapes ON that slide

  • Use the shape's .Top, .Left, .Height and .Width properties to set its position and size

Example:

Dim oSh As Shape

Set oSh = ActivePresentation.Slides(9).Shapes.PasteSpecial(ppPasteEnhancedMetafile)(1)
' .PasteSpecial returns a ShapeRange; the (1) at the end of the line above
' returns the first shape in the range. W/o that, you get a type mismatch error
' from trying to assign a range to a shape

With oSh
   ' Set position:
  .Left = 0
  .Top = 0
   ' Set size:
  .Height = 100
  .Width = 200
End With
Related Topic