Chop picture in VBA?
Thanks, Ben, but your code is not working???
I get a 'Method or data member not found'
....in this line: sPicture.PictureFormat.Crop
and the word '.Crop' is highlighted.
Only crop options I have a
..CropBottom
..CropLeft
..CropRight
..CropTop
Am I missing a reference or something???
CE
Den 21.12.2012 19:57, Ben McClave skrev:
Charlotte,
I think that the routine copied below will work. To recreate your workbook, I pasted a picture to the sheet and place a rectangle shape over it. After running the code below, the picture is cropped to fit inside the box. In addition, the code displays the compress picture dialog in case you would like to compress the picture afterwards. Simply comment out (or delete) those two lines if you dont' want to include that step.
Hope this helps.
Ben
Sub CropIt()
Dim sShape As Shape
Dim sPicture As Shape
Set sShape = Sheet1.Shapes("Rectangle 2")
Set sPicture = Sheet1.Shapes("Picture 3")
With sPicture.PictureFormat.Crop
.ShapeLeft = sShape.Left
.ShapeTop = sShape.Top
.ShapeWidth = sShape.Width
.ShapeHeight = sShape.Height
End With
'Comment out next two lines if you do not want to show compress dialog
sPicture.Select
Application.CommandBars.ExecuteMso "PicturesCompress"
Set sShape = Nothing
Set sPicture = Nothing
End Sub
|