1.锁定纵横比
Sub setpicsize()
On Error Resume Next '忽略错误
new_width_cm = 7.8 '设置新宽度
For Each iShape In ActiveDocument.InlineShapes '类型 图片
If iShape.Type = wdInlineShapePicture Then
iShape.LockAspectRatio = msoTrue '锁定纵横比
iShape.Width = CentimetersToPoints(new_width_cm) '宽
'Shap.Height = CentimetersToPoints(7) '高注释掉了
With iShape
.Range.ParagraphFormat.Reset
.Range.ParagraphFormat.Alignment = wdAlignParagraphCenter '居中
End With
End If
Next
End Sub
2.不锁定纵横比
Sub setpicsize()
On Error Resume Next '忽略错误
new_width_cm = 16 '设置新宽度
new_height_cm = 7 '设置新宽度
For Each iShape In ActiveDocument.InlineShapes '类型 图片
If iShape.Type = wdInlineShapePicture Then
iShape.LockAspectRatio = msoFalse '锁定纵横比
iShape.Width = CentimetersToPoints(new_width_cm) '宽16CM
Shap.Height = CentimetersToPoints(new_height_cm) '高7CM
With iShape
.Range.ParagraphFormat.Reset
.Range.ParagraphFormat.Alignment = wdAlignParagraphCenter '居中
End With
End If
Next
End Sub
3.相关链接
利用VBA宏批量解决Word中图片大小、居中设置https://www.cnblogs.com/dydxw/p/14340377.html