在Powerpoint中切换按钮

时间:2014-08-21 15:20:49

标签: vba button toggle powerpoint

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

一个。运行程序!!!我已删除所有内容并从头开始,除了我的第一个代码(见下文)并且没有其他任何内容。我需要什么来解决它。当我点击连接到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

1 个答案:

答案 0 :(得分:0)

您的代码将无法编译(打开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