PDA

View Full Version : Clearing Textboxes when slideshow closes (PowerPoint 2010)



JoeZarkos
02-08-2012, 07:40 AM
Hello,

I am using PowerPoint 2010, I have been making a PowerPoint that contains Textboxes. When I enter a value into these textboxes the value remains even when the slideshow has been closed.

How can I get these textboxes to clear when the slideshow closes.

My brain keeps going for the FormClosing event for Visual Basic but I don't know how to do this in VBA.

Thanks,

Joe

John Wilson
02-08-2012, 09:48 AM
See if this works for you (it's not completely reliable)

Sub OnSlideShowTerminate(Wn As SlideShowWindow)
Dim osld As Slide
Dim oshp As Shape
On Error Resume Next
For Each osld In ActivePresentation.Slides
For Each oshp In osld.Shapes
If oshp.Type = 12 Then
If oshp.OLEFormat.ProgID = "Forms.TextBox.1" Then
oshp.OLEFormat.Object.Text = ""
End If
End If
Next oshp
Next osld
End Sub

JoeZarkos
02-08-2012, 10:37 AM
Thanks that helped.

How about a macro for individual textboxes on slideshow end. As I forgot about one textbox that needs to remain uncleared.

Thanks,

Joe

John Wilson
02-08-2012, 12:09 PM
You would need some way of identifying it. eg if it's on slide 6

Sub OnSlideShowTerminate(Wn As SlideShowWindow)
Dim osld As Slide
Dim oshp As Shape
On Error Resume Next
For Each osld In ActivePresentation.Slides
If osld.SlideIndex <> 6 Then
For Each oshp In osld.Shapes
If oshp.Type = 12 Then
If oshp.OLEFormat.ProgID = "Forms.TextBox.1" Then
oshp.OLEFormat.Object.Text = ""
End If
End If
Next oshp
End If
Next osld
End Sub

JoeZarkos
02-08-2012, 01:31 PM
I should have made this clear before.

On slide 4, I have two textboxes. TextBox1 needs to be cleared, TextBox2 needs to be changed to "Correct: 0/3".

On slide 6, I have three textboxes. TextBox 1 and 3 need to be cleared, TextBox2 needs to be changed to "Correct: 0/4".

Thanks,

Joe

John Wilson
02-08-2012, 01:46 PM
Just set those two back to the text needed.
Sub OnSlideShowTerminate(Wn As SlideShowWindow)
Dim osld As Slide
Dim oshp As Shape
On Error Resume Next
For Each osld In ActivePresentation.Slides

For Each oshp In osld.Shapes
If oshp.Type = 12 Then
If oshp.OLEFormat.ProgID = "Forms.TextBox.1" Then
oshp.OLEFormat.Object.Text = ""
End If
End If
Next oshp

Next osld
ActivePresentation.Slides(4).Shapes("TextBox2").OLEFormat.Object.Text = "Correct: 0/3"
ActivePresentation.Slides(6).Shapes("TextBox2").OLEFormat.Object.Text = "Correct: 0/4"
End Sub

JoeZarkos
02-08-2012, 02:37 PM
Works a treat. Thank you, much appreciated.

Thanks,

Joe

John Wilson
02-09-2012, 12:13 AM
Just so you know we have seen some problems with the onslideshowterminate method. Sometimes it fails to fire after the presentation is saved and reopened. Our experience is it works well if VB has been manually accessed during the show so if someone changes a control textbox for example it should be fine. In more general situations it may fail.

johnwatkins3
11-15-2012, 02:43 PM
so will this work if users that are taking my quiz, they enter their name on slide one then on the last slide that has the certificate has their name from slide one.