【问题标题】:VBA in Powerpoint : Text Box ValuePowerpoint 中的 VBA:文本框值
【发布时间】:2016-06-29 23:56:38
【问题描述】:

我想比较powerpoint中2个文本框的值,突出显示数值最高的那个。

这是我的代码:

If ActivePresentation.Slides(4).Shapes("Rectangle 84").TextFrame.TextRange.Text.Value >= ActivePresentation.Slides(4).Shapes("Rectangle 95").TextFrame.TextRange.Text.Value Then XXXX

不幸的是,如果 Rectangle 84 的值为“11”,而 Rectangle 95 的值为 6,则当前 6 被突出显示。 有什么方法可以将文本转换为数值,以便我得到正确的结果?

谢谢 詹姆斯

【问题讨论】:

  • CIntCdbl 可以帮助您将文本转换为数字

标签: vba powerpoint


【解决方案1】:

尝试先将值转换为数字,例如使用CLng(转换为长整数)或CDbl(转换为双精度值)(如果您期望非整数)。

If CDbl(ActivePresentation.Slides(4).Shapes("Rectangle 84").TextFrame.TextRange.Text.Value) >= CDbl(ActivePresentation.Slides(4).Shapes("Rectangle 95").TextFrame.TextRange.Text.Value) Then XXXX

字符串"11""6"“小”,因为它们按字母顺序排序。

您还可以在转换之前使用IsNumeric 检查文本是否有效,以防止类型不匹配

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2012-07-17
    • 1970-01-01
    • 1970-01-01
    • 2021-02-02
    • 1970-01-01
    • 1970-01-01
    • 2014-04-05
    • 2017-01-25
    相关资源
    最近更新 更多