Word中的Visual Basic宏调整大小/居中/删除所有图像

5 ms-word word-vba

我在网上找到了一个VBA宏来调整Word文档中的所有图像:

Sub ResizeAllImages()
''# make all images (both inline and floating)
''# 11 cm wide while preserving aspect ratio

Dim oShp As Shape
Dim oILShp As InlineShape

For Each oShp In ActiveDocument.Shapes
    With oShp
        .Height = AspectHt(.Width, .Height, _
        CentimetersToPoints(11))
        .Width = CentimetersToPoints(11)
    End With
Next

For Each oILShp In ActiveDocument.InlineShapes
    With oILShp
        .Height = AspectHt(.Width, .Height, _
        CentimetersToPoints(11))
        .Width = CentimetersToPoints(11)
    End With
Next
End Sub
Run Code Online (Sandbox Code Playgroud)

我找不到可用于对齐所有图像的方法的名称.有谁知道我需要添加什么,以及我必须添加它的位置?

最后,我想删除我觉得太小的图片.我该怎么做...如果形状的宽度小于5,并且形状的高度小于5,则删除形状.

为了便于阅读大量在线文本,我有时希望将所有内容粘贴到单词中,然后重新排列.我用句号 - 手动线替换每个句点 - 空格,这为每个句子提供了一个新的行.我就读得更好了.由于我粘贴了所有东西,图形也来了,所以我希望能够控制所有图像的大小,并摆脱任何不必要的图像.

Doc*_*own 5

我认为您无法将图像居中对齐。您可以将段落居中对齐。也许这样的事情会帮助您:

For Each oILShp In ActiveDocument.InlineShapes
    oILShp.Select
    Selection.ParagraphFormat.Alignment = wdAlignParagraphCenter
Next
Run Code Online (Sandbox Code Playgroud)

对于删除,只需调用Delete满足您条件的每个Shape对象。