Consulting

Results 1 to 3 of 3

Thread: Vba in powerpoint to clear a text box

  1. #1
    VBAX Newbie
    Joined
    Oct 2019
    Posts
    1
    Location

    Vba in powerpoint to clear a text box

    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.

  2. #2
    VBAX Master
    Joined
    Feb 2007
    Posts
    2,096
    Location
    Post the code used to create the msgbox.
    John Wilson
    Microsoft PowerPoint MVP
    Amazing Free PowerPoint Tutorials
    http://www.pptalchemy.co.uk/powerpoi...tutorials.html

  3. #3
    Moderator VBAX Wizard Aussiebear's Avatar
    Joined
    Dec 2005
    Location
    Queensland
    Posts
    5,512
    Location
    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
    Remember To Do the Following....
    Use [Code].... [/Code] tags when posting code to the thread.
    Mark your thread as Solved if satisfied by using the Thread Tools options.
    If posting the same issue to another forum please show the link

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •