VBA PowerPoint显示和隐藏形状
我有几张PowerPoint幻灯片,其中有我喜欢显示和隐藏的对象(箭头和矩形)。目前我只使用VBA PowerPoint显示和隐藏形状,vba,powerpoint,Vba,Powerpoint,我有几张PowerPoint幻灯片,其中有我喜欢显示和隐藏的对象(箭头和矩形)。目前我只使用 ActivePresentation.Slides("Slide100").Shapes("Rectangle 99").Visible = False or True ActivePresentation.Slides("Slide100").Shapes("Straight Arrow Connector 118").Visible = False or True 现在可能需要删除该模板中的一个
ActivePresentation.Slides("Slide100").Shapes("Rectangle 99").Visible = False or True
ActivePresentation.Slides("Slide100").Shapes("Straight Arrow Connector 118").Visible = False or True
现在可能需要删除该模板中的一个矩形或箭头。这会在运行宏时导致VBA错误,因为找不到矩形或箭头。有没有办法编写一个宏来检查所有使用的矩形和箭头,然后隐藏或显示它们,而不是使用单个变量
我发现了这样的东西:
For Each sObject In ActivePresentation.Slides(2).Shapes
sObject.Visible = False
Next
但我只需要隐藏矩形和箭头,没别的
致意
Peter将该循环作为起点,并在其中应用一些逻辑。形状有两个有用的属性,
autoshapetype
和name
以下两个例子:
For Each shp In ActivePresentation.Slides(x).Shapes
If InStr(1, shp.Name, "Rectangle") > 0 Then
shp.Visible = False
End If
Next shp
或
以该循环为起点,在其中应用一些逻辑。形状有两个有用的属性,
autoshapetype
和name
以下两个例子:
For Each shp In ActivePresentation.Slides(x).Shapes
If InStr(1, shp.Name, "Rectangle") > 0 Then
shp.Visible = False
End If
Next shp
或
这将隐藏活动演示文稿中所有幻灯片上的所有矩形类型和箭头类型子集:
' PowerPoint VBA Macro
' Purpose : hide rectangles and shapes across slides
' Written by : Jamie Garroch of YOUpresent Ltd. http://youpresent.co.uk.
Sub HideRectanglesAndArrows()
Dim oSld As Slide
Dim oShp As Shape
For Each oSld In ActivePresentation.Slides
For Each oShp In oSld.Shapes
If oShp.Type = msoAutoShape Then
Select Case oShp.AutoShapeType
' Basic Arrows (4)
Case msoShapeUpArrow, msoShapeDownArrow, msoShapeLeftArrow, msoShapeRightArrow
oShp.Visible = msoFalse
' Double Arrows (2)
Case msoShapeUpDownArrow, msoShapeLeftRightArrow
oShp.Visible = msoFalse
' Add other arrow types as required
'
' Basic Rectangles (1)
Case msoShapeRectangle
oShp.Visible = msoFalse
' Rounded Rectangles (4)
Case msoShapeRound1Rectangle, msoShapeRound2DiagRectangle, msoShapeRound2SameRectangle, msoShapeRoundedRectangle
oShp.Visible = msoFalse
' Snipped Rectangles (4)
Case msoShapeSnip1Rectangle, msoShapeSnip2DiagRectangle, msoShapeSnip2SameRectangle, msoShapeSnipRoundRectangle
oShp.Visible = msoFalse
End Select
End If
Next
Next
End Sub
然后,可以使用.Name属性或位置属性(.Left、.Top)或大小属性(.Width、.Height)添加逻辑以删除特定形状。如果您想更详细(用户可以更改形状的名称),则可以向形状添加标记,以用户无法更改的方式标识它们,然后编写一个过程来检查逻辑中的.Tags属性。这将隐藏活动演示文稿中所有幻灯片中的所有矩形类型和箭头类型子集:
' PowerPoint VBA Macro
' Purpose : hide rectangles and shapes across slides
' Written by : Jamie Garroch of YOUpresent Ltd. http://youpresent.co.uk.
Sub HideRectanglesAndArrows()
Dim oSld As Slide
Dim oShp As Shape
For Each oSld In ActivePresentation.Slides
For Each oShp In oSld.Shapes
If oShp.Type = msoAutoShape Then
Select Case oShp.AutoShapeType
' Basic Arrows (4)
Case msoShapeUpArrow, msoShapeDownArrow, msoShapeLeftArrow, msoShapeRightArrow
oShp.Visible = msoFalse
' Double Arrows (2)
Case msoShapeUpDownArrow, msoShapeLeftRightArrow
oShp.Visible = msoFalse
' Add other arrow types as required
'
' Basic Rectangles (1)
Case msoShapeRectangle
oShp.Visible = msoFalse
' Rounded Rectangles (4)
Case msoShapeRound1Rectangle, msoShapeRound2DiagRectangle, msoShapeRound2SameRectangle, msoShapeRoundedRectangle
oShp.Visible = msoFalse
' Snipped Rectangles (4)
Case msoShapeSnip1Rectangle, msoShapeSnip2DiagRectangle, msoShapeSnip2SameRectangle, msoShapeSnipRoundRectangle
oShp.Visible = msoFalse
End Select
End If
Next
Next
End Sub
然后,可以使用.Name属性或位置属性(.Left、.Top)或大小属性(.Width、.Height)添加逻辑以删除特定形状。如果您希望更详细(用户可以更改形状的名称),则可以向形状添加标记,以用户无法更改的方式标识它们,然后编写一个过程来检查逻辑中的.Tags属性