1

我想问一下,为什么有时当我在选定的文本框上使用以下代码时,我会得到多个小数位的 msgbox 返回值(例如 3-6 位小数),有时它会返回一个相同的整数文本框

Sub getShapeNow()

With ActiveWindow.Selection.ShapeRange(1)

MsgBox .Name
MsgBox .Width
MsgBox .Height
MsgBox .Top
MsgBox .Left

End With


End Sub
4

1 回答 1

1

Powerpoint显然不支持任何 Width,而只支持一些 Width,这是基于屏幕分辨率的。因此,如果你尝试

Sub GetShapeNow()

    With ActiveWindow.Selection.ShapeRange(1)
        .Width = 47.00147
        Debug.Print .Width
    End With

End Sub

我会看到47.0015打印在即时窗口上,与我的Widthrezolution.00147不支持的一样。


属性是一个小数,逗号后面有值。如果逗号后没有值,例如47和 not 47.01,则将VBA值写为47

检查这个:

Sub GetShapeNow()

    With ActiveWindow.Selection.ShapeRange(1)
        .Width = 47
        .Height = 34
        .Top = 40.4
        .Left = 147
        Debug.Print .Name; .Width; .Height; .Top; .Left
    End With  

End Sub

在即时窗口中,您会看到以下内容:

Rectangle 1 47  34  40,4  147 

通常,Shape.Width返回的值来自 type Single

于 2018-04-30T08:52:18.113 回答