Resizing picture using Powerpoint vba

雨燕双飞 提交于 2019-12-12 17:17:48

问题


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.


回答1:


  • 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


来源:https://stackoverflow.com/questions/13169905/resizing-picture-using-powerpoint-vba

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!