首页 > 解决方案 > Word 宏 - 无需调整大小即可获取原始大小

问题描述

我想要一个宏来检查嵌入的 OLEObjects 的大小与它们的原始尺寸。当您尝试获取 Shapes 或 InlineShapes 的缩放属性时,您会得到无意义的数字(例如 0 ),因此我最终的解决方法是检查它们的大小,然后将大小调整为原始大小的 100%,然后检查该大小并进行比较。有没有更好的办法?

    For Each shp In ActiveDocument.Shapes
        If shp.Type = msoEmbeddedOLEObject Then
                sW = shp.Width
                sH = shp.Height
                shp.ScaleWidth 1#, msoTrue
                shp.ScaleHeight 1#, msoTrue
                sW = sW / shp.Width
                sH = sH / shp.Height
                shp.ScaleWidth sW, msoTrue
                shp.ScaleHeight sH, msoTrue
        End If
    Next
    For Each ishp In ActiveDocument.InlineShapes
        If ishp.Type = wdInlineShapeEmbeddedOLEObject Then
                sW = ishp.Width
                sH = ishp.Height
                ishp.ScaleWidth = 100
                ishp.ScaleHeight = 100
                sW = sW / ishp.Width
                sH = sH / ishp.Height
                ishp.ScaleWidth = sW * 100
                ishp.ScaleHeight = sH * 100
        End If
    Next

标签: vbams-wordresize

解决方案


推荐阅读