2013-12-10 108 views
1

我是VBA的新手(因爲今天早上所以請把我當成一個白癡,你會是正確的!),並堅持看起來像它應該非常簡單。PowerPoint VBA - 單擊形狀,然後按另一個形狀來改變顏色

我在PowerPoint中工作,並有一組圓圈,下方有一個紅色和一個綠色的方塊。

我希望能夠選擇一個相關的圓,然後點擊相應的平方來改變這個圈子只紅色或綠色,如下

Select your option: O   O   O    O    O 


Change colour:    [Red]     [Green] 

目前我使用的動畫和觸發器但我有很多圈子,我只想每次更換一個。

+0

如果你點擊一個圓,然後單擊廣場,重點將轉向從金環廣場。在這種情況下,你可以做的就是使用布爾變量,當你點擊特定的圓時,它會被激活,然後使用代碼顏色相關的形狀(圓形)。 –

回答

0

+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 
+0

非常感謝您的幫助。我會坐下來試着按照我的方式工作 - 看看我能理解的事情! –