0

我是 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
4

1 回答 1

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
于 2013-08-02T14:47:13.353 回答