Batch resize pictures in Word

When there are many pictures in a document and the size of the pictures needs to be adjusted, you can use "macro" to execute the code to adjust the size in batches.

  1. Open a Word document.

  1. "Alt+F8" key opens macro.

  1. Set the "Macro Name" and click "Create".

  1. After creating the macro, you will enter the Visual Basic editor interface.

  1. Select all in the code editing area, delete the previous code, and then copy and paste the following code.

Sub setpicsize() '设置图片大小

    Dim n '图片个数

    Dim picwidth

    Dim picheight

    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 * 0.9 '设置高度为0.9倍

    ActiveDocument.InlineShapes(n).Width = picwidth * 0.9 '设置宽度为0.9倍

    Next n

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

    picheight = ActiveDocument.Shapes(n).Height

    picwidth = ActiveDocument.Shapes(n).Width

    ActiveDocument.Shapes(n).Height = picheight * 0.9 '设置高度为0.9倍

    ActiveDocument.Shapes(n).Width = picwidth * 0.9 '设置宽度为0.9倍

    Next n

    End Sub

Here is to set the image to be scaled by 0.9. If you want to set the image to have a fixed width and height, please refer to the following content.

 ActiveDocument.InlineShapes(n).Height = 400 '设置图片高度为 400px
  ActiveDocument.InlineShapes(n).Width = 300 '设置图片宽度 300px
  1. Paste the code below and click Save.

  1. Return to the Word document editing interface and press "Alt+F8" to open the macro. At this time, the newly created macro already exists, and the name is changed to the function name of the code. Click "Run" to realize batch adjustment of pictures.

Article links for reference are as follows.

https://product.pconline.com.cn/itbk/software/word/1404/4642700.html

https://www.51zxw.net/TechArticleDetails.aspx?id=2001

Guess you like

Origin blog.csdn.net/qq_38250687/article/details/129165879