可通过VBA宏批量调整Word中所有图片尺寸:①启用开发工具并插入模块;②运行ScaleAllPicturesByRatio按比例缩放;③运行SetAllPicturesToFixedSize设固定像素;④运行ResizeAllPicturesByWidth按宽自适应缩放。

如果您在Word文档中插入了多张图片,且需要将它们统一调整为相同的长宽比例,手动逐个设置效率低下。以下是通过宏脚本批量调整图片(含嵌入型与浮动型)形状尺寸的具体操作步骤:
一、启用开发工具并创建宏
Word默认不显示“开发工具”选项卡,需先启用该功能,才能录制或编辑宏代码。启用后可新建模块并粘贴VBA脚本,实现对所有图片的批量处理。
1、点击“文件”→“选项”→“自定义功能区”,在右侧勾选“开发工具”,点击“确定”。
2、切换到“开发工具”选项卡,点击“Visual Basic”打开VBA编辑器。
3、在左侧工程资源管理器中,右键“Normal”→“插入”→“模块”,新建一个空白模块。
4、在模块编辑窗口中粘贴后续步骤中的任一VBA代码。
二、使用固定比例缩放所有图片
该方法保持原始图片的宽高比不变,仅按指定比例统一放大或缩小,适用于需维持图像清晰度和构图关系的场景。
1、在模块中输入以下代码:
Sub ScaleAllPicturesByRatio()
Dim shp As InlineShape
Dim shpF As Shape
Dim ratio As Single
ratio = 0.8 ' 修改此处数值:1.0=原尺寸,0.5=缩为一半,1.2=放大1.2倍
For Each shp In ActiveDocument.InlineShapes
If shp.Type = wdInlineShapePicture Then
shp.ScaleHeight = ratio * 100
shp.ScaleWidth = ratio * 100
End If
Next shp
For Each shpF In ActiveDocument.Shapes
If shpF.Type = msoPicture Or shpF.Type = msoLinkedPicture Then
shpF.ScaleHeight ratio, msoTrue
shpF.ScaleWidth ratio, msoTrue
End If
Next shpF
End Sub
三、强制设定统一像素尺寸(覆盖原始比例)
该方法将所有图片直接设为指定宽度与高度(单位:磅),忽略原有长宽比,适用于排版严格对齐、制作标准化报告等需求。注意可能导致图片变形。
1、在模块中输入以下代码:
Sub SetAllPicturesToFixedSize()
Dim shp As InlineShape
Dim shpF As Shape
Dim targetW As Single, targetH As Single
targetW = 200 ' 单位为磅,1英寸=72磅,约等于2.78厘米
targetH = 150 ' 可根据需要修改这两个值
For Each shp In ActiveDocument.InlineShapes
If shp.Type = wdInlineShapePicture Then
shp.Width = targetW
shp.Height = targetH
End If
Next shp
For Each shpF In ActiveDocument.Shapes
If shpF.Type = msoPicture Or shpF.Type = msoLinkedPicture Then
shpF.Width = targetW
shpF.Height = targetH
End If
Next shpF
End Sub
四、按指定宽度自适应缩放(保持原始比例)
该方法以目标宽度为基准,自动计算对应高度,确保所有图片在宽度一致的前提下不发生拉伸或压缩,适合图文混排中统一图宽的场景。
1、在模块中输入以下代码:
Sub ResizeAllPicturesByWidth()
Dim shp As InlineShape
Dim shpF As Shape
Dim baseWidth As Single
baseWidth = 250 ' 设定统一宽度,单位为磅
For Each shp In ActiveDocument.InlineShapes
If shp.Type = wdInlineShapePicture Then
shp.Width = baseWidth
shp.Height = shp.Height * (baseWidth / shp.Width)
End If
Next shp
For Each shpF In ActiveDocument.Shapes
If shpF.Type = msoPicture Or shpF.Type = msoLinkedPicture Then
shpF.LockAspectRatio = msoTrue
shpF.Width = baseWidth
End If
Next shpF
End Sub
五、运行宏并保存更改
宏编写完成后需执行才能生效,执行前建议备份原文档以防误操作导致格式异常。运行后Word会立即遍历并修改所有符合条件的图片对象。
1、关闭VBA编辑器,返回Word主界面。
2、点击“开发工具”→“宏”,在列表中选择已创建的宏名称(如“ScaleAllPicturesByRatio”)。
3、点击“运行”按钮,等待处理完成(无提示即表示已完成)。
4、按“Ctrl + S”保存文档,确保尺寸变更被持久化。










