我希望 PowerPoint 演示文稿的第一张幻灯片上有多个形状,这些形状会根据特定幻灯片上是否有图片或链接的 Excel 表格而变成绿色或灰色。基本上一个形状指的是演示文稿的一张幻灯片,以便在查看第一张幻灯片时,您可以看到哪些主题(幻灯片)已填充信息(即图片或链接的表格)。
我创建了一个宏,可以将其作为单击操作放置在第一张幻灯片上的形状后面,当在演示模式下单击形状时,该宏会将其颜色更改为绿色或灰色。这适用于引用不同幻灯片的多个形状,但必须手动单击每个形状才能更新(绿色/灰色)。
目标是当打开演示文稿时(显示第一张幻灯片),形状后面的所有宏都会自动执行,以查看第一张幻灯片上显示的当前情况。
我可以想象的一种方法是在第一张幻灯片上的中性形状后面设置一个宏,这样当单击该形状时就会执行一个宏,该宏会执行放置在其他形状后面的所有宏并相应地更改它们的颜色。我无法编写点击第一张幻灯片上的每个形状一次的代码。
另一种方法是使用一个代码,扫描第一张幻灯片上的所有形状,获取应检查哪张幻灯片的图片/表格以更改其颜色的信息,然后更改颜色。我没有成功。
这是根据特定幻灯片上的信息(图片/表格)更改颜色的工作代码。如何在输入第一张幻灯片时自动单击或更新状态?
Sub Shape_Clickfor2(ByVal shp As shape)
Dim hasImageOrTable As Boolean
hasImageOrTable = False
'Überprüfen, ob auf Folie 2 ein Bild oder eine Tabelle vorhanden ist
Dim slideShapes As Shapes
Set slideShapes = ActivePresentation.Slides(2).Shapes
Dim shape As shape
For Each shape In slideShapes
If shape.Type = msoPicture Or shape.Type = msoEmbeddedOLEObject Then
hasImageOrTable = True
Exit For
End If
Next shape
'Farbe der Form ändern
If hasImageOrTable = True Then
shp.Fill.ForeColor.RGB = RGB(0, 255, 0) 'grün
Else
shp.Fill.ForeColor.RGB = RGB(128, 128, 128) 'grau
End If
End Sub
您可以循环播放演示文稿中的所有幻灯片(不包括第一张幻灯片)并更新第一张幻灯片上命名形状(“slide_2”、“slide_3”等)的填充
Sub Shape_Clickfor2(ByVal shp As shape)
Dim hasImageOrTable As Boolean, sld As Slide, shape As shape
hasImageOrTable = False
For Each sld In ActivePresentation.Slides 'loop all slides
If sld.SlideIndex > 1 Then 'skip slide 1
hasImageOrTable = False 'reset flag
For Each shape In sld.Shapes
If shape.Type = msoPicture Or shape.Type = msoEmbeddedOLEObject Then
hasImageOrTable = True
Exit For
End If
Next shape
'update color for named shape on slide 1 based on flag value
With ActivePresentation.Slides(1).Shapes("slide_" & sld.SlideIndex)
.Fill.ForeColor.RGB = IIf(hasImageOrTable, _
RGB(0, 255, 0), _
RGB(128, 128, 128))
End With
End If 'not slide 1
Next sld
End Sub
这是使用
SlideID
的版本:
Sub Shape_Clickfor2(ByVal shp As shape)
Dim hasImageOrTable As Boolean, sld As Slide, shape As shape, id, obj As shape
hasImageOrTable = False
For Each sld In ActivePresentation.Slides 'loop all slides
Set shape = Nothing
On Error Resume Next 'ignore error if no match
'is there a shape for this slide's ID?
Set shape = ActivePresentation.Slides(1).Shapes("slide_" & sld.SlideID)
On Error GoTo 0 'stop ignoring errors
If Not shape Is Nothing Then 'got a shape?
hasImageOrTable = False 'reset flag
For Each obj In sld.Shapes
If obj.Type = msoPicture Or obj.Type = msoEmbeddedOLEObject Then
hasImageOrTable = True
Exit For
End If
Next obj
shape.Fill.ForeColor.RGB = IIf(hasImageOrTable, _
RGB(0, 255, 0), _
RGB(128, 128, 128))
End If
Next sld
End Sub