言成说 - 图片尺寸
type: channel
link: https://elecdiy.com/tag/%E5%9B%BE%E7%89%87%E5%B0%BA%E5%AF%B8/
items: WORD使用宏命令批量按比例设置处理图片尺寸大小

WORD使用宏命令批量按比例设置处理图片尺寸大小
type: item
date: 2021-03-15T17:26:00+08:00
description: 将下方宏命令copy到命令窗口中并点击运行即可，也无需保存，即可[scode type="red"]注意，n需要替换为实际值：如15,单位是cm[/scode]（1）设置固定大小n厘米： Sub resetImgSize() Dim iShape As InlineShape For Each iShape In ActiveDocument.InlineShapes iShape.LockAspectRatio = msoTrue iShape.Height = CentimetersToPoints(n) iShape.Width = CentimetersToPoints(n) Next End Sub （2）等比例缩放n倍： Sub resetImgSize() Dim imgHeight Dim imgWidth Dim iShape As InlineShape For Each iShape In ActiveDocument.InlineShapes iShape.LockAspectRatio = msoTrue imgHeight = iShape.Height imgWidth = iShape.Width iShape.Height = CentimetersToPoints(n * imgHeight ) iShape.Width = CentimetersToPoints(n * imgWidth) Next End Sub （3）最大宽度n厘米等比例缩放： Sub resetImgSize() Dim imgHeight Dim imgWidth Dim iShape As InlineShape For Each iShape In ActiveDocument.InlineShapes iShape.LockAspectRatio = msoTrue imgHeight = iShape.Height imgWidth = iShape.Width iShape.Height = CentimetersToPoints(n * imgHeight / imgWidth) iShape.Width = CentimetersToPoints(n) Next End Sub 如果想对同一文件夹下的word进行批量处理 ，可参考下文：[post cid="114" cover="https://www.elecdiy.com/usr/uploads/time/604f2825c995d.jpg"/]