office VBA批量裁剪
Sub 裁剪()
percentToCropB =25
percentToCropL = 8
percentToCropR = 5
percentToCropT =48
Dim n '图片个数
On Error Resume Next '忽略错误
For n = 1 To ActiveDocument.InlineShapes.Count 'InlineShapes类型图片
With ActiveDocument.InlineShapes(n).PictureFormat
origHeight = ActiveDocument.InlineShapes(n).Height
origWidth = ActiveDocument.InlineShapes(n).Width
cropPointsB = origHeight * percentToCropB / 100
cropPointsL = origWidth * percentToCropL / 100
cropPointsR = origHeight * percentToCropR / 100
cropPointsT = origWidth * percentToCropT / 100
.CropBottom = cropPointsB
.CropLeft = cropPointsL
.CropRight = cropPointsR
.CropTop = cropPointsT
End With
Next n
For n = 1 To ActiveDocument.Shapes.Count 'Shapes类型图片
With ActiveDocument.Shapes(n).PictureFormat
origHeight = ActiveDocument.Shapes(n).Height
origWidth = ActiveDocument.Shapes(n).Width
cropPointsB = origHeight * percentToCropB / 100
cropPointsL = origWidth * percentToCropL / 100
cropPointsR = origHeight * percentToCropR / 100
cropPointsT = origWidth * percentToCropT / 100
.CropBottom = cropPointsB
.CropLeft = cropPointsL
.CropRight = cropPointsR
.CropTop = cropPointsT
End With
Next n
End Sub