使用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. 然后点击运行即可
相关推荐
Sunflower023 小时前
如何解决word/WPS word 中表格跳到下一页(上一页有大篇幅空白)
word·wps
AI导出鸭1 天前
如何让deepseek生成word文档 ?「AI 导出鸭」苹果版:从API流式解析到Pages级渲染,硬核攻克公式裂变与表格回流的终极方案。
人工智能·chatgpt·word·cocoa·ai导出鸭
开开心心就好1 天前
Word双击预览图片插件弥补Word功能缺失
人工智能·python·智能手机·ocr·电脑·word·音视频
一棵星2 天前
内网 MySQL 表结构一键导出 Word 文档:直连 + Agent 双模式实战
数据库·mysql·word
bug嘛我经常写2 天前
如何批量删除word文档中存在的无用样式
经验分享·python·word
Am-Chestnuts3 天前
Kimi长回答批量导出Word:DS随心转实践
word
曹牧3 天前
Word:更改列表级别
word
wtsolutions4 天前
Sheet-to-Doc Skill: Let AI Assistants Generate Word Documents for You
人工智能·word
qq_466302456 天前
如何在word中添加代码
word
一棵星6 天前
LibreOffice Word 转 PDF 报错 “source file could not be loaded” 完整解决方案
pdf·word