2013-06-24 50 views
1

在此先感谢。在PowerPoint中检查多种形状VBA

我在幻灯片(B01 - B44)上有44个形状,我想检查它们是否不包含字母“A”。还有其他形状我想从搜索中排除。我想这样做没有一堆“和”,但我对VBA来说有点新鲜。

喜欢的东西:

If ActivePresentation.Slides(2).Shapes("B##").TextFrame.TextRange.Text <> "A" Then MsgBox "No A's" 

回答

0

您可以在一个循环做到这一点:

Dim i as Long, a As Long 
Dim shp as Shape 
Dim pres as Pres: Set pres = ActivePresentation 

For i = 1 to 44 
    Set shp = pres.Slides(2).Shapes("B" & i) 
    If shp.TextFrame.TextRange.Text <> "A" Then 
     aCount = aCount+1 
    End If 
Next 

If aCount = 0 Then 
    MsgBox "No A's were found" 
Else: 
    MsgBox aCount & " A's were found" 
End If 

注意:此检查是否文本 “A”,而不是它是否包含字母“A”。

+0

这工作除了我只有什么“然后”发生,如果所有的形状没有A的。你有什么建议吗? 非常感谢! –

+0

看到我修改后的答案。这只会告诉你*有多少*,而不是哪些形状包含它们。要做后者,你需要使用数组,字典或集合。 –

+0

优秀!谢谢! –

相关问题