网站Logo 美好的邂逅~相遇开始

Word VBA图片大小统一设置

suzhe
31
2023-07-02
使用下面代码设置统一大小
  1. 打开 Microsoft Word,按下 “Alt + F11” 键进入 VBA 编辑器。

  2. 在 “Project” 窗口中,右键单击 “Microsoft Word Object”,选择 “Insert” > “Module” 来创建一个新模块。

  3. 在新模块中,输入以下代码来实现简单的图片大小统一任务:

Sub Example()
    Dim oInlineShape As InlineShape
    Application.ScreenUpdating = False
    For Each oInlineShape In ActiveDocument.InlineShapes
        With oInlineShape.Borders
            .OutsideLineStyle = wdLineStyleSingle
            .OutsideColorIndex = wdColorAutomatic
            .OutsideLineWidth = wdLineWidth050pt
        End With
    Next
    Application.ScreenUpdating = True
End Sub


Sub FormatPics()
Dim TuPian As InlineShape
For Each TuPian In ActiveDocument.InlineShapes
If TuPian.Type = wdInlineShapePicture Then
TuPian.LockAspectRatio = msoFalse '不锁定图片的宽高比
TuPian.Width = CentimetersToPoints(7.2) '设置图片宽度为10CM
TuPian.Height = CentimetersToPoints(7.5) '设置图片高度为8CM
End If
Next
End Sub
  1. 按下 “F5” 键来运行宏。
动物装饰