在WORD中批量修改图片大小

今天在word中批量修改图片时发现了word一个强大的功能,不多说废话,直接附上步骤:

1.首先按一定的顺序将图片插入word当中;
2.点击“视图”----“宏”,再选择“查看宏”;
3.在宏名中输入自己定义的名字,这里名字定义为“daxiao”
4.输入以下代码:

Sub daxiao()'这个宏的名字是daxiao
Dim n  '图片个数
On Error Resume Next   '忽略错误
For n=1 To ActiveDocument.InlineShapes.Count
ActiveDocument.InlineShapes(n).Height=5*28.5   '设置图片高为5cm
ActiveDocument.InlineShapes(n).Width=4*28.5    '图片宽为4cm
Next n
End Sub

PS:若想设置统一宽度或统一高度则可用以下代码来实现:

Sub 设为统一宽度()

    Dim n '图片个数

    Dim picwidth

    Dim picheight

    Dim newWidth

    newWidth = 300 '设置图片的统一宽度

    On Error Resume Next '忽略错误

    For n = 1 To ActiveDocument.InlineShapes.Count 'InlineShapes 类型图片

        picheight = ActiveDocument.InlineShapes(n).Height

        picwidth = ActiveDocument.InlineShapes(n).Width

        ActiveDocument.InlineShapes(n).Height = picheight * newWidth / picwidth

        ActiveDocument.InlineShapes(n).Width = newWidth

    Next n

    For n = 1 To ActiveDocument.Shapes.Count 'Shapes类型图片

        picheight = ActiveDocument.Shapes(n).Height

        picwidth = ActiveDocument.Shapes(n).Width

        Debug.Print picheight

        ActiveDocument.InlineShapes(n).Height = picheight * newWidth / picwidth

        ActiveDocument.InlineShapes(n).Width = newWidth

    Next n

End Sub

Sub 设为统一高度()

    Dim n '图片个数

    Dim picwidth

    Dim picheight

    Dim newHeight

    newHeight = 200 '设置统一高度时修改此数值

    On Error Resume Next '忽略错误

    For n = 1 To ActiveDocument.InlineShapes.Count 'InlineShapes 类型图片

        picheight = ActiveDocument.InlineShapes(n).Height

        picwidth = ActiveDocument.InlineShapes(n).Width

        ActiveDocument.InlineShapes(n).Height = newHeight

        ActiveDocument.InlineShapes(n).Width = picwidth * newHeight / picheight

    Next n

    For n = 1 To ActiveDocument.Shapes.Count 'Shapes类型图片

        picheight = ActiveDocument.Shapes(n).Height

        picwidth = ActiveDocument.Shapes(n).Width

        Debug.Print picheight

        ActiveDocument.InlineShapes(n).Height = newHeight

        ActiveDocument.InlineShapes(n).Width = picwidth * newHeight / picheight

    Next n

End Sub

以上就是word中批量修改图片大小的方法,在后来的使用中,还查到可以将图片保存为较老版本的word,即doc格式,可以直接批量修改图片大小和格式,但不建议这样做,因为这样容易使得图片格式混乱,不易后面的使用和排版。

  • 2
    点赞
  • 8
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

GISerQ.

你的鼓励将是我创作的最大动力。

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值