宏命令对word里的图片尺寸大小进行批量修改(按比例修改)
Sub 批量调整图片尺寸()
'锁定图片的纵横比
'设置图片大小(1cm=28.35px)
SizeHeight = 22.33 * 28.35 '设置图片高度
SizeWidth = 15.78 * 28.35 '设置图片宽度
SizeProportion = SizeHeight / SizeWidth '纵横比
Dim n '图片个数
On Error Resume Next '忽略错误
For n = 1 To ActiveDocument.InlineShapes.Count 'InlineShapes类型图片
ActiveDocument.InlineShapes(n).LockAspectRatio = msoTrue '解除纵横比锁定
PictureHeight = ActiveDocument.InlineShapes(n).Height
PictureWidth = ActiveDocument.InlineShapes(n).Width
PictureProportion = PictureHeight / PictureWidth '纵横比
If (PictureProportion > SizeProportion) Then
ActiveDocument.InlineShapes(n).Height = SizeHeight '设置图片高度
ActiveDocument.InlineShapes(n).Width = ((SizeHeight) / PictureHeight) * PictureWidth '设置图片宽度
ElseIf (PictureProportion <= SizeProportion) Then
ActiveDocument.InlineShapes(n).Width = SizeWidth '设置图片宽度
ActiveDocument.InlineShapes(n).Height = ((SizeWidth) / PictureWidth) * PictureHeight '设置图片高度
Else
ActiveDocument.InlineShapes(n).Height = SizeHeight '设置图片高度
ActiveDocument.InlineShapes(n).Width = SizeWidth '设置图片宽度
End If
Next n
Application.ScreenUpdating = True
End Sub
这篇博客介绍了一种使用VBA宏的方法,通过锁定图片纵横比并按预设比例批量调整Word文档中图片的尺寸,提高编辑效率。
1万+

被折叠的 条评论
为什么被折叠?



