VBA_批量调整图片宽度

'版心尺寸大小(假设 Word 2003 中,A4纵向纸张,宽度已知是21厘米,左边距2.5厘米,右边距2.5厘米,所以,版心尺寸=宽度-左边距-右边距=16厘米)
    Dim Width As Single, Left As Single, Right As Single
    Width = Round(ActiveDocument.PageSetup.PageWidth / 28.35)
    Left = Round(ActiveDocument.PageSetup.LeftMargin / 28.35, 1)
    Right = Round(ActiveDocument.PageSetup.RightMargin / 28.35, 1)
    MsgBox "版心尺寸是 " & (Width - Left - Right) & " 厘米"


Sub 图片宽度批量调整()
Dim i
Dim j
Dim oldHeight
Dim oldWidth
Dim newHeight
Dim newWidth
Dim docWidth
docWidth = 15 * 28.345

On Error Resume Next
For i = 1 To ActiveDocument.InlineShapes.Count
 oldWidth = ActiveDocument.InlineShapes(i).Width
 oldHeight = ActiveDocument.InlineShapes(i).Height
 '如果长度大于内容区的长度则自动修改图片长度为内容区,图片高度按照比例压缩
 If oldWidth > docWidth Then
     newWidth = docWidth
     newHeight = newWidth * oldHeight / oldWidth
 End If
 ActiveDocument.InlineShapes(i).Height = newHeight '修改为自己需要的值
 ActiveDocument.InlineShapes(i).Width = newWidth '修改为自己需要的值

Next
For j = 1 To ActiveDocument.Shapes.Count
  oldWidth = ActiveDocument.InlineShapes(i).Width
  oldHeight = ActiveDocument.InlineShapes(i).Height
 '如果长度大于内容区的长度则自动修改图片长度为内容区,图片高度按照比例压缩
 If oldWidth > docWidth Then
     newWidth = docWidth
     newHeight = newWidth * oldHeight / oldWidth
 End If
 ActiveDocument.InlineShapes(j).Height = newHeight '修改为自己需要的值
 ActiveDocument.InlineShapes(j).Width = newWidth '修改为自己需要的值

Next

End Sub
  • 0
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值