fodia 在您的示例中未定义,因此很难猜测它应该是什么。但我认为这不是问题的根源。这是另一种有效的方法。有几点需要注意:
PPT 对 ActiveX 对象的处理很奇怪。要获得您习惯用于控制对象的属性,您必须使用 Shape.OLEFormat.Object.property_name
并且至少在某些版本中,ActiveX 形状不会以正常的形状顺序出现;您可以通过幻灯片上的形状依次选择每个形状,但永远不会选择 ActiveX 形状。命名形状是一种解决方法(并且在重新排序形状时不会改变,因此它更可靠一些)。
Sub RedOrGreen()
Dim mainslide As Slide
Dim oSh As Shape
Set mainslide = ActivePresentation.Slides(1)
Set oSh = FindShapeNamed("green", mainslide)
If Not oSh Is Nothing Then
oSh.OLEFormat.Object.Picture = LoadPicture("c:\temp\red.jpg")
oSh.Name = "red"
Exit Sub
End If
Set oSh = FindShapeNamed("red", mainslide)
If Not oSh Is Nothing Then
oSh.OLEFormat.Object.Picture = LoadPicture("c:\temp\green.jpg")
oSh.Name = "green"
Exit Sub
End If
End Sub
Function FindShapeNamed(sName As String, oSl As Slide) As Shape
Dim oSh As Shape
For Each oSh In oSl.Shapes
If oSh.Name = sName Then
Set FindShapeNamed = oSh
Exit Function
End If
Next
End Function