【问题标题】:Toggle Buttons in PowerpointPowerpoint 中的切换按钮
【发布时间】:2014-08-21 15:20:48
【问题描述】:

我正在尝试将切换按钮插入到 powerpoint 的多个页面中。我有按钮可以按我想要的方式运行,但现在我看不到做两件事:

A.运行程序!!!除了我的第一个代码(见下文)之外,我已经删除了所有内容并从头开始,并且没有其他任何内容。我需要什么来修复它。当我单击连接到 YourName() 的形状时,没有任何反应。

B.我想在开始时将按钮的值设置为 0。一旦运行,你认为我的代码会这样做吗?

谢谢

Sub YourName()
Dim userName As String
Dim ToggleButton1 As ToggleButton
Dim ToggleButton2 As ToggleButton
Dim ToggleButton3 As ToggleButton
Dim ToggleButton4 As ToggleButton
Dim done As Boolean

done = False
While Not done
userName = InputBox(Prompt:="My name is", Title:="Input Name")
   If userName = "" Then
    done = False
Else
    done = True
End If
Wend

FeedbackAnswered = False

ActivePresentation.Slides(2).ToggleButton("ToggleButton1").Value = 0
ActivePresentation.Slides(2).ToggleButton("ToggleButton2").Value = 0
ActivePresentation.Slides(2).ToggleButton("ToggleButton3").Value = 0
ActivePresentation.Slides(2).ToggleButton("ToggleButton4").Value = 0


ActivePresentation.SlideShowWindow.View.Next

End Sub

【问题讨论】:

    标签: vba button toggle powerpoint


    【解决方案1】:

    您的代码无法编译(打开 IDE,打开代码所在的模块,选择 Debug | Compile)。当您尝试在幻灯片放映中运行损坏的代码时(就像您正在做的那样),PPT 不会发出任何错误消息,它根本不会尝试运行代码。

    这至少可以编译;我没有时间创建具有正确形状的演示文稿,但是,嘿,不得不为您留下一些乐趣:

    Option Explicit
    
    Sub YourName()
    Dim userName As String
    
    ' Dim these as Object; there's no such thing as ToggleButton
    Dim ToggleButton1 As Object
    Dim ToggleButton2 As Object
    Dim ToggleButton3 As Object
    Dim ToggleButton4 As Object
    Dim done As Boolean
    ' You forgot one:
    Dim FeedbackAnswered As Boolean
    
    done = False
    While Not done
    userName = InputBox(Prompt:="My name is", Title:="Input Name")
       If userName = "" Then
        done = False
    

    ' 你可能想在这里添加一个 Exit Sub,否则可怜的 '用户没有出路

    Else
        done = True
    End If
    Wend
    
    FeedbackAnswered = False
    
    ' Fixed these too:
    ActivePresentation.Slides(2).Shapes("ToggleButton1").OLEFormat.Object.Value = 0
    ActivePresentation.Slides(2).Shapes("ToggleButton2").OLEFormat.Object.Value = 0
    ActivePresentation.Slides(2).Shapes("ToggleButton3").OLEFormat.Object.Value = 0
    ActivePresentation.Slides(2).Shapes("ToggleButton4").OLEFormat.Object.Value = 0
    
    
    ActivePresentation.SlideShowWindow.View.Next
    
    End Sub
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-12-27
      • 2021-06-17
      • 2017-05-21
      • 1970-01-01
      • 2018-02-23
      • 2016-11-14
      • 2014-09-12
      • 2014-04-25
      相关资源
      最近更新 更多