PDA

View Full Version : [SLEEPER:] Vba in powerpoint to clear a text box



mc6145
10-22-2019, 10:38 AM
Hello,

I'm developing a Powerpoint to work as an interactive "program" for an escape-room type activity. The user enters different account numbers into a text box (Command Button ActiveX Control) and depending on what is entered, a MsgBox appears, providing them with information. My question is... in VBA, how do I clear the textbox after the user clicks the OK button on the message box? Something like If OKonly Then textbox1.clear... but cannot get my code correct.

John Wilson
10-22-2019, 04:50 PM
Post the code used to create the msgbox.

Aussiebear
07-12-2025, 12:26 PM
Sub ClearTextboxOnResponse()
Dim userChoice As VbMsgBoxResult
Dim shp As Shape
' Show a message box with Yes/No buttons
userChoice = MsgBox("Do you want to clear the text box?", vbYesNo + vbQuestion, "Clear Text")
If userChoice = vbYes Then
' Reference the shape named "TextBox1" on the current slide
Set shp = ActivePresentation.SlideShowWindow.View.Slide.Shapes("TextBox1")
' Clear the text
shp.TextFrame.TextRange.Text = ""
End If
End Sub


I'm assuming you are in Slide show view (using SlideShowWindow.View.Slide) and there is a shape named TextBox1 on the current slide.

If you're not in Slideshow mode then change:


Set shp = ActivePresentation.SlideShowWindow.View.Slide.Shapes("TextBox1")

to


Set shp = ActivePresentation.Slides(1).Shapes("TextBox1") ' Replace "1" with your slide number