Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ajax/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
PowerPoint VBA-单击形状,然后按另一个形状以更改颜色_Vba_Powerpoint - Fatal编程技术网

PowerPoint VBA-单击形状,然后按另一个形状以更改颜色

PowerPoint VBA-单击形状,然后按另一个形状以更改颜色,vba,powerpoint,Vba,Powerpoint,我是VBA的新手(从今天早上开始,所以请把我当作白痴对待,你大概是对的!)我被困在一些看起来应该很简单的事情上 我在PowerPoint中工作,有一组圆圈,下面是红色和绿色的正方形 我希望能够选择一个相关的圆圈,然后单击相应的正方形,将该圆圈仅更改为红色或绿色,如下所示 Select your option: O O O O O Change colour: [Red]

我是VBA的新手(从今天早上开始,所以请把我当作白痴对待,你大概是对的!)我被困在一些看起来应该很简单的事情上

我在PowerPoint中工作,有一组圆圈,下面是红色和绿色的正方形

我希望能够选择一个相关的圆圈,然后单击相应的正方形,将该圆圈仅更改为红色或绿色,如下所示

 Select your option:   O         O          O              O             O


 Change colour:              [Red]                  [Green]

目前我正在使用动画和触发器,但我有很多圆圈,我只想一次更改一个

+1向悉达思寻求答案。如果你刚刚开始,还有一点是不明显的。您可以让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

如果单击一个圆,然后单击正方形,焦点将从一个圆移到另一个正方形。在这种情况下,您可以使用布尔变量,当您单击特定的圆时,
激活
,然后使用代码颜色相关的形状(圆)非常感谢您的帮助。我会坐下来,努力解决这个问题——看看我能理解什么!