保持图片原始比例(锁定横纵比例)的情况下,批量调整为适应页面尺寸的图片大小。
LockAspectRatio - 锁定横纵比例, MsoTrue if the specified shape retains its original proportions when you resize it. MsoFalse if you can change the height and width of the shape independently of one another when you resize it. Read/write MsoTriState.
wdInlineShapeLinkedPicture - 嵌入式连接图片(一般浏览器复制过来的图片类型)
wdInlineShapePicture - 嵌入式图片
P.S. 2019.8.8 更新代码
代码如下:
Sub ResizePhotos()
Dim Shap As InlineShape
Dim maxWith
maxWith = CentimetersToPoints(16.79)
For Each Shap In ActiveDocument.InlineShapes
Debug.Print Shap.Type; "Shap.Type"; wdInlineShapePicture
If (Shap.Type = wdInlineShapeLinkedPicture) Or (Shap.Type = wdInlineShapePicture) Then
If Shap.Width > maxWith Then
' Shap.LockAspectRatio = msoTrue
Debug.Print "before width: "; Shap.Width
Debug.Print "before Height: "; Shap.Height
oW = Shap.Width
oH = Shap.Height
aspect = oH / oW 'aspect ratio
nH = aspect * CentimetersToPoints(16.79) 'new width
Shap.Width = CentimetersToPoints(16.79)
Shap.Height = nH
Debug.Print "after width: "; Shap.Width
Debug.Print "after Height: "; Shap.Height
End If
End If
Next
End Sub
其中, 16.79 为厘米单位的A4页面宽度,CentimetersToPoints为厘米转像素的函数
点击左上角的文件-选项-自定义功能区,勾选左侧的"开发工具"
此时,文档功能区出现开发工具
点击宏,或者使用快捷点Alt + F8,打开宏管理,创建名为ResizePhotos的宏函数
复制粘贴代码即可
方法一、 在编辑窗口按F5即可
方法二、在管理窗口选中函数,点击运行
https://superuser.com/questions/940771/how-can-i-resize-multiple-images-in-a-ms-word-document
https://zhuanlan.zhihu.com/p/42588748
https://answers.microsoft.com/en-us/office/forum/office_2010-word/creating-a-macro-for-resizing-several-photos-in/b251f117-8d17-4522-bac4-d128c32587ba
https://docs.microsoft.com/en-us/office/vba/api/word.wdinlineshapetype