Resizing a picture image to fixed height and then cropped width

Christea685

New Member
Joined
Jan 24, 2014
Messages
35
Hi All!

I'm trying to make this macro work to help resize images for our fashion Look Book. In theory, it should work. But of course it does not Here is the code we are using:

Code:
Sub BIGcrop()




Selection.Height = 507.6


x = Selection.ShapeRange.Width
y = x / 2
Z = y - 144




Selection.ShapeRange.PictureFormat.CropLeft = Z + 185
Selection.ShapeRange.PictureFormat.CropRight = Z + 185


Selection.ShapeRange.LockAspectRatio = msoFalse


Selection.ShapeRange.Width = 288


Selection.ShapeRange.LockAspectRatio = msoTrue




End Sub

I want all my pictures to have a height of 7.05 inches and a width of 4. The height comes out different everytime depending on the scaling of the template I'm using. I need it to adjust accordingly. I'm open to having the image move into merged cells (I read about someone doing that here) as long as it will first adjust the height and then crop the sides (so the orientation stays the same). Any help/suggestions would be SO appreciated!
 

Excel Facts

VLOOKUP to Left?
Use =VLOOKUP(A2,CHOOSE({1,2},$Z$1:$Z$99,$Y$1:$Y$99),2,False) to lookup Y values to left of Z values.
Have you tried "Picture Resizer 6.0" which will do all the dimensioning outside of excel, then you won't end up with too much manipulation in excel
 
Upvote 0
I wanted to post the code I ended up with, incase anyone else needs to do something similar:

Code:
Sub BIGcrop()
 
Dim x, y, z As Double
 
With ActiveSheet.Shapes("Rectangle 92")
    Selection.Height = .Height
   
 
x = Selection.ShapeRange.Width 'Whole Picture
y = x / 5.45 ' Model Width
z = (x - y) '/ 4 'Width on either side of Model
 
Selection.ShapeRange.LockAspectRatio = msoFalse
 
Selection.ShapeRange.PictureFormat.CropLeft = x - z
Selection.ShapeRange.PictureFormat.CropRight = x - z
 
End With
 
With ActiveSheet.Shapes("Rectangle 92")
    Selection.Top = .Top
    Selection.Left = .Left
   
End With
 
Selection.ShapeRange.ZOrder msoSendToBack
 
End Sub

This code takes the height of the rectangle box on the template (that needs to be replaced by my new picture image), adjusts the picture height accordingly, then crops a portion of each side (you can adjust this by altering what "y" equals).
 
Upvote 0
Upvote 0

Forum statistics

Threads
1,215,455
Messages
6,124,937
Members
449,195
Latest member
Stevenciu

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top