RubyFuse
asked on
Crop a picture in Powerpoint
I would like to know what is wrong with my code below as the cropped image does not end up the right size.
i need the macro to resize the selected image to 12.71cm wide, then to crop off evenly from the top and bottom the left over image above the required height, 3.4cm. There may be instances where the original image is portrait shape but regardless, its needing to be 3.4 x 12.71 in the end.
Sub CropPic()
Dim oSlide As Slide
Dim oPicture As Shape
Dim oshpR As ShapeRange
Dim fd As FileDialog
Dim strFile As String
Dim sngCropSize As Single
' Set oSlide to the first slide in the presentation.
Set oSlide = ActiveWindow.View.Slide
Set oPicture = ActiveWindow.Selection.Sha peRange(1)
oPicture.Width = 363.14
sngCropSize = oPicture.Height - 97.14
oPicture.PictureFormat.Cro pTop = sngCropSize / 2
oPicture.PictureFormat.Cro pBottom = sngCropSize / 2
Set oshpR = oSlide.Shapes.Range(Array( oPicture.N ame))
End Sub
i need the macro to resize the selected image to 12.71cm wide, then to crop off evenly from the top and bottom the left over image above the required height, 3.4cm. There may be instances where the original image is portrait shape but regardless, its needing to be 3.4 x 12.71 in the end.
Sub CropPic()
Dim oSlide As Slide
Dim oPicture As Shape
Dim oshpR As ShapeRange
Dim fd As FileDialog
Dim strFile As String
Dim sngCropSize As Single
' Set oSlide to the first slide in the presentation.
Set oSlide = ActiveWindow.View.Slide
Set oPicture = ActiveWindow.Selection.Sha
oPicture.Width = 363.14
sngCropSize = oPicture.Height - 97.14
oPicture.PictureFormat.Cro
oPicture.PictureFormat.Cro
Set oshpR = oSlide.Shapes.Range(Array(
End Sub
96 should probably be 96.34 I think
ASKER
Hi JSRWilson
Unfortunately this still doesn't get the right height, even with the 96.34 changed. My end height is 7.45 which is half of the original height.
Any other suggestions?
Thanks Ruby
Unfortunately this still doesn't get the right height, even with the 96.34 changed. My end height is 7.45 which is half of the original height.
Any other suggestions?
Thanks Ruby
Did you use all of the code?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Yes, used all of the code.
The ammended code seems to do it here.
ASKER
Excellent, thanks!
ASKER
If I were to do this for an image size of
ASKER
Sorry, if I was to do this for an image size of 3.29 x 3.4cm what would need to change? I added in the dimensions but got a result with a minus crop measurement which mean parts of the image were transparent. Happy to post this as a separate question if need be.
If you get a negative value it would mean it's impossible to crop to this size. (it's already less)
You would need to set the height and crop left & right maybe.
You would need to set the height and crop left & right maybe.
If you have 2007 onwards you can use a picture placeholder which will auto crop BTW
Try:
Open in new window