显示/隐藏控件文本框

时间:2013-08-02 14:28:30

标签: vba powerpoint powerpoint-vba

我是Visual Basic的新手,我不明白这项任务需要什么对象。

我有5个“控制文本框”,我想在Powerpoint中隐藏显示。我有以下代码并收到424错误:

Private Sub CommandButton1_Click()
  Activesheet.oleobjects("TextBox2").Visible = False
  Activesheet.oleobjects("TextBox9").Visible = False
  Activesheet.oleobjects("TextBox8").Visible = False
  Activesheet.oleobjects("TextBox7").Visible = False
  Activesheet.oleobjects("TextBox6").Visible = False
End Sub

Private Sub CommandButton2_Click()
  Activesheet.oleobjects("TextBox2").Visible = True
  Activesheet.oleobjects("TextBox9").Visible = True
  Activesheet.oleobjects("TextBox8").Visible = True
  Activesheet.oleobjects("TextBox7").Visible = True
  Activesheet.oleobjects("TextBox6").Visible = True
End Sub

1 个答案:

答案 0 :(得分:1)

PowerPoint没有工作表,因此没有Activesheet对象。这将立即引发错误。要简单地切换可见性,您可以执行以下操作:

Sub ToggleVisibility()
    With ActivePresentation.Slides(1)
        .Shapes("TextBox1").Visible = Not .Shapes("TextBox1").Visible
        .Shapes("TextBox2").Visible = Not .Shapes("TextBox2").Visible
        ' and so on
    End With
End Sub