检查对象的属性是否有值

时间:2019-02-11 16:42:03

标签: vba powerpoint powerpoint-vba

我无法在SO或其他来源上找到解决方案。如果这是一个令人厌倦的问题,我提前致歉:

我有一个宏,它通过形状中的占位符进行迭代。其中一些占位符带有文本,有些则没有。我想弄清楚是否 .Shapes.Placeholder.TextFrame.TextRange是否具有任何值(在VBA编辑器的“监视”部分中,该属性具有<The specified value is out of range.>)。如果可以,请执行某些操作。否则,继续执行For Each语句。但是,我尝试的所有内容都超出了范围错误或此类错误。

我尝试过:

  • If Not (placeholder.TextFrame.TextRange.Length = 0) Then:立即抛出界外错误
  • 尝试/捕获,在VBA中似乎不存在(给我Sub或Function未注册)
  • If Not CStr(placeholder.TextFrame.TextRange) = "0" then

由于我没有任何Visual Basic迭代的经验,因此我非常不精通。我只需要,如果该属性为空或null,则跳过占位符。

编辑:根据建议,我尝试了此操作:

For Each placeholder In sld.NotesPage.Shapes.Placeholders
    If Not (placeholder.TextFrame Is Nothing) Then
        If Not (placeholder.TextFrame.TextRange Is Nothing) Then
            If Not (placeholder.TextFrame.TextRange.LanguageID Is Nothing) Then
                placeholder.TextFrame.TextRange.LanguageID = lng
            End If
        End If
    End If
Next

我仍然在placeholder.TextFrame.TextRange Is Nothing上遇到错误。我有语法错误吗?

最终编辑:事实证明,SO中毕竟有answer。对于此特定问题,在On Error Resume Next之后添加For Each就足够了。

0 个答案:

没有答案