futrueface

  博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理
  46 随笔 :: 1 文章 :: 2 评论 :: 36997 阅读

Sub AdjustImagesWidthPreserveAspectRatio()
Dim doc As Document
Dim shp As InlineShape
Dim img As Shape

Set doc = ActiveDocument ' 设置当前活动文档

' 设置图片宽度(以厘米为单位),高度将保持不变
Dim newWidthCm As Single
newWidthCm = 21.1 ' 例如,将图片宽度设置为10厘米(设置为动态获取文档宽度,一直运行会有问题,没有解决,只能设置为固定宽度)

' 将厘米转换为点数(Word中使用)
Dim newWidthPnt As Single
newWidthPnt = CentimetersToPoints(newWidthCm)

' 遍历文档中的所有内嵌形状
For Each shp In doc.InlineShapes
Set img = shp.ConvertToShape ' 转换为Shape对象以便修改

' 锁定纵横比
img.LockAspectRatio = msoTrue

' 设置环绕方式为嵌入型
img.WrapFormat.Type = wdWrapInline

' 保持原始高度,只调整宽度
img.Width = newWidthPnt ' 设置新的宽度
Next shp

MsgBox "图片宽度调整完成!"
End Sub

 

posted on   futrueface  阅读(20)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· TypeScript + Deepseek 打造卜卦网站:技术与玄学的结合
· Manus的开源复刻OpenManus初探
· 三行代码完成国际化适配,妙~啊~
· .NET Core 中如何实现缓存的预热?
· 阿里巴巴 QwQ-32B真的超越了 DeepSeek R-1吗?
点击右上角即可分享
微信分享提示