VBA PowerPoint 显示和隐藏形状 [英] VBA PowerPoint Display and Hide Shapes

查看:47
本文介绍了VBA PowerPoint 显示和隐藏形状的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有几张 PowerPoint 幻灯片,其中包含我喜欢显示和隐藏的对象(箭头和矩形).目前我只是使用

I have several PowerPoint slides with objects (arrows and rectangles) I like to display and hide. At the moment I just use

ActivePresentation.Slides("Slide100").Shapes("Rectangle 99").Visible = False or True

ActivePresentation.Slides("Slide100").Shapes("Straight Arrow Connector 118").Visible = False or True

现在可以在该模板中删除一个矩形或箭头.当您运行宏时,这会导致 VBA 错误,因为找不到矩形或箭头.有没有办法写一个宏来检查所有使用的矩形和箭头,然后隐藏或显示它们而不是使用单个变量?

Now it can be that one rectangle or arrow has to be deleted in that template. This leads to VBA errors when you run the macro because the rectangle or arrow couldn't be found. Is there any way to write a macro to check all the used rectangles and arrows and then hides or displays them all instead of using single variables?

我发现了这样的东西:

For Each sObject In ActivePresentation.Slides(2).Shapes
sObject.Visible = False
Next

但我只需要隐藏矩形和箭头,仅此而已.

But I just need to hide rectangles and arrows, nothing more.

最好的问候彼得

推荐答案

以该循环为起点并在其中应用一些逻辑.形状有两个可能有用的属性,autoshapetypename

Take that loop as a starting point and apply some logic within it. There are two properties of the shape that could be useful, autoshapetype and name

以下两个示例:

For Each shp In ActivePresentation.Slides(x).Shapes
    If InStr(1, shp.Name, "Rectangle") > 0 Then
        shp.Visible = False
    End If
Next shp

For Each shp In ActivePresentation.Slides(x).Shapes
    If shp.AutoShapeType = msoShapeRectangle Then
        shp.Visible = False
    End If
Next shp

这篇关于VBA PowerPoint 显示和隐藏形状的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆