PDA

View Full Version : Macro to crop pictures



shruti1
11-17-2020, 06:53 AM
I was just introducing you to some of the controls. Here is the fish.

Lets say you have a 1/2 white border around the image.

Sub CropDemo()
Dim oILS As InlineShape
Set oILS = Selection.InlineShapes(1)
With oILS
.PictureFormat.CropLeft = 36
.PictureFormat.CropTop = 36
.PictureFormat.CropRight = 36
.PictureFormat.CropBottom = 36
End With
With oILS
.LockAspectRatio = True
.Height = 360
End With
lbl_Exit:
Exit Sub
End Sub


I want to crop all the pictures at once in my document. Please help

gmaxey
11-17-2020, 07:35 AM
You would start by writing some code. Something like this would be helpful:

For Each oILS In ActiveDocument.InlineShapes

shruti1
11-17-2020, 07:11 PM
You would start by writing some code. Something like this would be helpful:<br>
<br>
For Each oILS In ActiveDocument.InlineShapes<br>

I tried this but got error "Compile error: For without next"
Sub Crop()
Dim oILS As InlineShape
Set oILS = Selection.InlineShapes(1)
For Each oILS In ActiveDocument.InlineShapes
With oILS
.PictureFormat.CropLeft = 36
.PictureFormat.CropTop = 36
.PictureFormat.CropRight = 36
.PictureFormat.CropBottom = 36
End With
With oILS
.LockAspectRatio = True
.Height = 360
End With
lbl_Exit:
Exit Sub
End Sub

gmaxey
11-18-2020, 07:56 AM
That would imply that you are missing the Next statement. If you do something "For" one item in a collections then when done, you would want to do it for the Next item in the collection.

For Each ...
'Do something
Next

You also don't need the the Set oILS statement in the above code.