+1給Siddharth的答案。如果你剛剛開始,還有一點是不明顯的。當形狀觸發一個宏時,你可以讓PPT傳遞一個被點擊的形狀的引用(注意:Mac PPT是馬車/不完整的,這在那裏不起作用)。
使用亞洲時報Siddharth的建議爲起跳點,你可以做這樣的事情:
Option Explicit
Sub SelectMe(oSh As Shape)
' assign this macro to each of the shapes you want to color
' saves time to assign it to one shape, then copy the shape as many
' times as needed.
ActivePresentation.Tags.Add "LastSelected", oSh.Name
End Sub
Sub ColorMeRed(oSh As Shape)
' assign this macro to the "color it red" shape
' when this runs because you clicked a shape assigned to run the macro,
' oSh will contain a reference to the shape you clicked
' oSh.Parent returns a reference to the slide that contains the shape
' oSh.Parent.Shapes(ActivePresentation.Tags("LastSelected")) returns a reference
' to the shape whose name is contained in the "LastSelected" tag,
' which was applied in the SelectMe macro above.
' Whew!
If Len(ActivePresentation.Tags("LastSelected")) > 0 Then
With oSh.Parent.Shapes(ActivePresentation.Tags("LastSelected"))
.Fill.ForeColor.RGB = RGB(255, 0, 0)
End With
End If
End Sub
Sub ColorMeBlue(oSh As Shape)
' assign this macro to the "color it blue" shape
If Len(ActivePresentation.Tags("LastSelected")) > 0 Then
With oSh.Parent.Shapes(ActivePresentation.Tags("LastSelected"))
.Fill.ForeColor.RGB = RGB(0, 0, 255)
End With
End If
End Sub
如果你點擊一個圓,然後單擊廣場,重點將轉向從金環廣場。在這種情況下,你可以做的就是使用布爾變量,當你點擊特定的圓時,它會被激活,然後使用代碼顏色相關的形狀(圓形)。 –