0

I wrote a macro to batch crop and resize the pictures in selected slides, the resize work good, but after I added the crop codes, it is not working. Please see the codes as below, is there any thing wrong? welcome and thanks suggestion.

Sub crpicture ()
Dim osld As Slide
Dim oshp As Shape

For Each osld In ActiveWindow.Selection.SlideRange
For Each oshp In osld.Shapes

 oshp.PictureFormat.CropLeft = 0
 oshp.PictureFormat.CropTop = 0.5 * 72
 oshp.PictureFormat.CropRight = oshp.Width - oshp.Height
 oshp.PictureFormat.CropBottom = 0

 oshp.Height = 3 * 72
 oshp.Left = 3.4 * 72
 oshp.Top = 0.7 * 72
 oshp.ZOrder msoSendToBack

      Next
 Next
 End Sub
Tim Williams
  • 154,628
  • 8
  • 97
  • 125
together
  • 413
  • 2
  • 11
  • 1
    "It's not working" means what *exactly* - best not to make us guess if you know what the problem is... – Tim Williams Sep 29 '15 at 16:08
  • can not run ask to debug. oshp.PictureFormat.CropLeft = 0 oshp.PictureFormat.CropTop = 0.5 * 72 oshp.PictureFormat.CropRight = oshp.Width - oshp.Height oshp.PictureFormat.CropBottom = 0 shows yellow, I do not know where and why these codes wrong – together Sep 30 '15 at 05:15
  • 1
    Shapes only have a `PictureFormat` if they are a picture or an OLEObject: https://msdn.microsoft.com/en-us/library/office/ff745665.aspx If there are shapes on your slides which aren't either of those two then you'll need to test for that. What's the error message/number you get? – Tim Williams Sep 30 '15 at 06:05
  • I fixed the problem. thanks – together Oct 08 '15 at 16:33

0 Answers0