PDA

View Full Version : code to setup crop dimension



Nikola_123
11-04-2022, 07:33 AM
Hello everyone,

I need help with macro code to crop the picture to some size, but not finish the crop process, only set it up where the grey edges are still visible.

Let's say I take some constant like, height=10cm, width=15cm, then the crop rectangle is set but I still need to move the picture around.

That way I can automatically have the dimension of the final photo, but still have time to manually readjust the crop area.

Anybody already knows the solution somewhere online? I didn't find anything that helps me.

Thank you in advance!

June7
11-04-2022, 05:44 PM
When you want new VBA code in Excel, use Macro Recorder. I got this much from doing that:

ActiveSheet.Shapes.Range(Array("Picture 2")).Select
Selection.ShapeRange.LockAspectRatio = msoFalse
Selection.ShapeRange.IncrementTop -5.1
Selection.ShapeRange.PictureFormat.Crop.PictureWidth = 75
Selection.ShapeRange.PictureFormat.Crop.PictureHeight = 75
Selection.ShapeRange.PictureFormat.Crop.PictureOffsetX = 5
Selection.ShapeRange.PictureFormat.Crop.PictureOffsetY = 6

Don't really know if you will get what you want.

I don't get the 'crop rectangle' shown in your image. Wait a minute, I see where that is now. Unfortunately, macro recorder does not record any code that activates the 'crop rectangle'.

Nikola_123
11-08-2022, 07:55 AM
When you want new VBA code in Excel, use Macro Recorder. I got this much from doing that:

ActiveSheet.Shapes.Range(Array("Picture 2")).Select
Selection.ShapeRange.LockAspectRatio = msoFalse
Selection.ShapeRange.IncrementTop -5.1
Selection.ShapeRange.PictureFormat.Crop.PictureWidth = 75
Selection.ShapeRange.PictureFormat.Crop.PictureHeight = 75
Selection.ShapeRange.PictureFormat.Crop.PictureOffsetX = 5
Selection.ShapeRange.PictureFormat.Crop.PictureOffsetY = 6

Don't really know if you will get what you want.

I don't get the 'crop rectangle' shown in your image. Wait a minute, I see where that is now. Unfortunately, macro recorder does not record any code that activates the 'crop rectangle'.


June,
Exactly, I get already cropped photo with macros. That is where I am stuck now, I don't have ability to re-locate photo before final cropping.

Does anybody know the solution?

Thanks in advance