使用word中的VBA 批量设置Word中所有图片大小

在VBA编辑器中,你可以创建、编辑和运行VBA宏代码,以实现自动化任务和自定义Word 功能。如果你是VBA编程初学者,可以在VBA编辑器中查看Word VBA宏代码示例,以便更好地了解如何使用VBA编写代码。

要打开VBA编辑器,你可以按照以下步骤:

  1. 文件-选项-自定义功能区-开发工具打上对钩-确定。
  1. 开发工具-visual basic

  2. 插入-模块

  1. 在其中粘贴以下内容:
python 复制代码
Sub FormatPics()

Dim Shap As InlineShape

For Each Shap In ActiveDocument.InlineShapes

If Shap.Type = wdInlineShapePicture Then

Shap.LockAspectRatio = msoTrue '锁定纵横比

Shap.Width = CentimetersToPoints(16) '宽16CM

End If

Next

End Sub

也可以不锁定纵横比:

python 复制代码
Sub FormatPics

Dim Shap As InlineShape

For Each Shap In ActiveDocument.InlineShapes

If Shap.Type = wdInlineShapePicture Then

Shap.LockAspectRatio = msoFalse '不锁定纵横比

Shap.Width = CentimetersToPoints(10) '宽10CM

Shap.Height = CentimetersToPoints(7) '高7CM

End If

Next

End Sub
  1. 然后点击运行即可
相关推荐
萧鼎11 小时前
深入解析 Python 的 Word 模板引擎:docxtpl 全面指南
开发语言·python·word
炒茄子11 小时前
Word:解决关于目录中各级标题的点/前导符粗细大小样式不一的问题
word
缺点内向11 小时前
C#: 如何自动化创建Word可填写表单,告别手动填写时代
c#·自动化·word
Knight_AL12 小时前
docx4j vs LibreOffice:Java 中 Word 转 PDF 的性能实测
java·pdf·word
wtsolutions1 天前
Sheet-to-Doc实际应用案例:从邀请函到获奖通知
word
bu_shuo1 天前
将AI生成的数学公式正确复制到word中
人工智能·chatgpt·word·latex
为自己_带盐1 天前
在 Blazor Server 中集成 docx-preview.js 实现高保真 Word 预览
javascript·c#·word
公子如琢2 天前
在word方框中打√符号☑☒
word
筱歌儿3 天前
TinyMCE-----word表格本地图片转base64并上传
前端·word