在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格式,可以直接批量修改图片大小和格式,但不建议这样做,因为这样容易使得图片格式混乱,不易后面的使用和排版。

发布了17 篇原创文章 · 获赞 25 · 访问量 5665

猜你喜欢

转载自blog.csdn.net/qq_44894692/article/details/90674966