Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/vba/15.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,我想我已经成功了! 睡了一夜好觉后,我又试了一次。我一直在复制和重命名隐藏我的代码和形状。选择框时,这不会显示最终形状。我没有复制,而是插入了一个新的最终形状,看起来很有效 我还删除了“让我看不见”代码,而是使用David Marcovitz的代码来显示隐藏的形状(如下)。我想我可能最终得到了相当混乱和冗长的代码,但它似乎正在工作。如果有人能帮我编写一个不那么麻烦的代码,我将不胜感激 Dim userName As String Sub GetStarted() Initialize

我想我已经成功了! 睡了一夜好觉后,我又试了一次。我一直在复制和重命名隐藏我的代码和形状。选择框时,这不会显示最终形状。我没有复制,而是插入了一个新的最终形状,看起来很有效

我还删除了“让我看不见”代码,而是使用David Marcovitz的代码来显示隐藏的形状(如下)。我想我可能最终得到了相当混乱和冗长的代码,但它似乎正在工作。如果有人能帮我编写一个不那么麻烦的代码,我将不胜感激

Dim userName As String
Sub GetStarted()
    Initialize
    ActivePresentation.SlideShowWindow.View.Next
End Sub
Sub Initialize()
    ActivePresentation.Slides("Slide1") _
        .Shapes("a").Visible = True
我为每个形状添加了一个true或false


几年前,汤姆·诺兰(Tom Nolan)提出了一个关于“VBA for Powerpoint中是否隐藏语句”的问题

他的问题是:“我有4个盒子,我有动画,当它们被点击时,它们会淡出。有没有可能有一个宏可以识别所有4个盒子何时消失,然后在第五个盒子中淡出? 因此,4个框在用户控件上消失,然后一旦它们全部消失,第五个框将自动出现。”

需要编码,因为人们可以/会随机选择盒子。史蒂夫·林德斯伯格(Steve Rindsberg)用一个密码回答(张贴在下面)

我已经成功地使用了它(感谢史蒂夫),但我想扩展它的选项。 e、 g.用户随机单击方框1-4,出现方框5,如Tom的场景所示。在同一张幻灯片上,用户可以单击方框6-9,当方框6-9消失时,会出现方框10。框1-4和6-9可以按任意顺序单击

通过修改Steve的代码可以做到这一点吗?由于我对编码的知识非常有限,我尝试了一些事情,但没有成功。 提前谢谢

史蒂夫的代码:

    ' Give each of the four shapes an action setting of Run Macro:  HideMe

    Sub HideMe(oSh As Shape)
        Dim oSl As Slide

    ' hide the clicked shape
        oSh.Visible = False

    ' test to see if all four shapes are hidden now
        ' edit to reflect the actual names of the shapes in use

    Set oSl = oSh.Parent    ' the slide containing the clicked shape
        With oSl
            If Not .Shapes("Rectangle 3").Visible Then
                If Not .Shapes("Rectangle 4").Visible Then
                    If Not .Shapes("Rectangle 5").Visible Then
                        If Not .Shapes("Rectangle 6").Visible Then
                            ' they're all hidden, so make the new shape visible
                            .Shapes("Rectangle 7").Visible = True
                        End If
                    End If

        End If
                End If

    ' Add this to handle the next four shapes

            If Not .Shapes("Rectangle 10").Visible Then
            If Not .Shapes("Rectangle 11").Visible Then
                If Not .Shapes("Rectangle 12").Visible Then
                    If Not .Shapes("Rectangle 13").Visible Then
                            ' they're all hidden, so make the new shape visible
                            .Shapes("Rectangle 13").Visible = True
                        End If
                    End If

                End If
            End If
        End With

    End Sub

    Sub MakeMeInvisible()
    ' run this after selecting the final shape
    ' to make it invisible to begin with
        ActiveWindow.Selection.ShapeRange(1).Visible = False
    End Sub

看看我的编辑是否对你有用太好了!!非常感谢你的这个@Steve。比我的尝试要整洁得多。终于让一切按我所希望的那样运作了。当然,现在我还想做更多的事情:)我对这件事太陌生了,以至于我的愿望远远超过了我的技能。很幸运有这样的论坛和像你这样的人来帮助。再次感谢。