I asked chatgtp: create vba code for powerpoint where a visitor can enter text as a response to a survey question and that text upon clicking on a enter button saves to csv file in documents folder

Todd Morgan 0 Reputation points
2026-11-15T16:53:27.5533333+00:00

And this was response:

Got it — you want a PowerPoint VBA macro that lets a visitor type a survey response into a textbox, click an Enter button, and have that response saved to a CSV file in the Documents folder.

Below is a complete, runnable VBA solution with robust input validation and error handling.

VBA Code for PowerPoint

Vba
Copy code
Option Explicit

' This macro saves the text from a PowerPoint shape (textbox) to a CSV file in the user's Documents folder.
Sub SaveSurveyResponse()
    Dim slide As slide
    Dim txtShape As Shape
    Dim btnShape As Shape
    Dim response As String
    Dim filePath As String
    Dim fileNum As Integer
    
    On Error GoTo ErrHandler
    
    ' Change these names to match your textbox and button shape names in PowerPoint
    Const TEXTBOX_NAME As String = "SurveyTextBox"
    
    ' Get the active slide
    Set slide = ActivePresentation.Slides(ActiveWindow.View.Slide.SlideIndex)
    
    ' Find the textbox shape
    Set txtShape = slide.Shapes(TEXTBOX_NAME)
    
    ' Get the text entered by the visitor
    response = Trim(txtShape.TextFrame.TextRange.Text)
    
    ' Validate input
    If Len(response) = 0 Then
        MsgBox "Please enter a response before clicking Enter.", vbExclamation, "Missing Response"
        Exit Sub
    End If
    
    ' Build file path in Documents folder
    filePath = Environ("USERPROFILE") & "\Documents\SurveyResponses.csv"
    
    ' Open file for append
    fileNum = FreeFile
    Open filePath For Append As #fileNum
    
    ' Write response to CSV (quoted to handle commas)
    Print #fileNum, """" & Replace(response, """", """""") & """"
    
    ' Close file
    Close #fileNum
    
    MsgBox "Your response has been saved. Thank you!", vbInformation, "Saved"
    
    Exit Sub
    
ErrHandler:
    MsgBox "An error occurred: " & Err.Description, vbCritical, "Error"
End Sub

How to Set Up in PowerPoint

  1. Create the Textbox
    • Insert a textbox on your slide.
    • Right-click → Rename Shape (in Selection Pane) → name it SurveyTextBox.
  2. Create the Enter Button
    • Insert a shape (e.g., rectangle) labeled "Enter".
    • Right-click → Assign Macro → choose SaveSurveyResponse.
  3. Enable Macros
    • Save your presentation as Macro-Enabled (.pptm).
    • Enable macros when opening.
  4. Test
    • Type a response in the textbox.
    • Click the Enter button.
    • Check your Documents folder for SurveyResponses.csv.

I can't seem to get the text box to appear as a field to input response in... any advice?

Microsoft 365 and Office | PowerPoint | For business | Windows
0 comments No comments

3 answers

Sort by: Newest
  1. Hani-Ng 2,935 Reputation points Independent Advisor
    2026-11-15T17:14:01.75+00:00

    Hi Todd Morgan

    From the description and code provided, the setup seems to rely on a standard PowerPoint text box (Insert > Text Box). Standard text boxes are generally intended for displaying content and may not support direct user input during Slide Show mode.

    If you are using the desktop version of PowerPoint for Windows, there are some VBA- and ActiveX-based approaches that may allow text entry. However, these solutions have limitations and may not work in all environments. Many organizations restrict or disable ActiveX controls for security reasons, and ActiveX/VBA solutions are not supported in PowerPoint for the web or PowerPoint Live in Microsoft Teams.

    To better understand your scenario, could you let me know:

    • Are you running the presentation in the PowerPoint desktop application for Windows?
    • Will the presentation be used on a single local computer, or will multiple attendees be submitting responses?
    • Do you specifically need the responses saved to a local CSV file?

    If your goal is to collect responses from attendees, you may also want to consider Microsoft Forms. Forms can be inserted into a PowerPoint presentation or shared through a link or QR code, allowing participants to submit responses directly. Responses are collected automatically and can be exported to Excel without requiring VBA macros or ActiveX controls.

    Additionally, if your organization's IT administrator restricts or disables ActiveX controls through security policies, you may be unable to insert or use an ActiveX Text Box in PowerPoint. In that case, an alternative approach may be to use a VBA InputBox prompt that appears when a button is clicked, or to collect responses through Microsoft Forms instead.

    I hope this information helps.

    Was this answer helpful?


  2. Todd Morgan 0 Reputation points
    2026-11-15T17:00:05.1966667+00:00

    How can I make it so that when you hit enter it advances to the next slide?

    Was this answer helpful?


  3. AI answer

    2026-11-15T16:54:22.7133333+00:00

    A regular PowerPoint text box cannot accept visitor input during a slide show; replace it with an ActiveX TextBox, then read its Text property through OLEFormat.Object.

    Create the input field

    This solution requires PowerPoint for Windows desktop. ActiveX controls are not supported in PowerPoint for Mac or PowerPoint for the web.^1^

    1. If Developer is not visible, open File → Options → Customize Ribbon, select Developer, and click OK.
    2. Open the survey slide.
    3. Select Developer → More Controls.
    4. Choose Microsoft Forms 2.0 TextBox, click OK, and draw the field on the slide.
    5. With the control selected, open Developer → Properties and set:
      • (Name): SurveyTextBox
      • MultiLine: True if visitors may enter multiple lines
    6. Start the presentation with Slide Show → From Current Slide and click inside the field.

    An ActiveX control remains in design mode while editing the presentation and becomes interactive when the slide show runs.^2^

    Do not use Insert → Text Box for the response field. That creates a PowerPoint Shape whose text is intended for slide content, not an interactive slide-show input control.^3^

    Use corrected VBA

    Press Alt+F11, select Insert → Module, and paste this code:

    Option Explicit
    
    Public Sub SaveSurveyResponse()
        Dim sld As Slide, ctl As Object
        Dim response As String, filePath As String
        Dim fileNum As Integer
    
        On Error GoTo Failed
    
        Set sld = SlideShowWindows(1).View.Slide
        Set ctl = sld.Shapes("SurveyTextBox").OLEFormat.Object
        response = Trim$(ctl.Text)
    
        If Len(response) = 0 Then
            MsgBox "Please enter a response.", vbExclamation
            Exit Sub
        End If
    
        'Remove line breaks so each response remains one CSV record.
        response = Replace(response, vbCrLf, " ")
        response = Replace(response, vbCr, " ")
        response = Replace(response, vbLf, " ")
    
        filePath = CreateObject("WScript.Shell") _
                       .SpecialFolders("MyDocuments") & "\SurveyResponses.csv"
    
        fileNum = FreeFile
        Open filePath For Append As #fileNum
        Print #fileNum, """" & Replace(response, """", """""") & """"
        Close #fileNum
    
        ctl.Text = ""
        MsgBox "Your response was saved.", vbInformation
        Exit Sub
    
    Failed:
        If fileNum > 0 Then Close #fileNum
        MsgBox "The response could not be saved: " & Err.Description, vbCritical
    End Sub
    

    OLEFormat.Object returns the embedded control’s object interface, allowing the macro to retrieve its Text value.^4^

    Using Windows’ configured Documents location avoids assuming that the folder is always %USERPROFILE%\Documents; this matters when Documents has been redirected, including some OneDrive configurations.

    Add the Enter button

    A normal shape can remain the button:

    1. Select Insert → Shapes and draw a button.
    2. Enter the label Enter.
    3. Select the button, then Insert → Action.
    4. Under Mouse Click, select Run macro.
    5. Choose SaveSurveyResponse and click OK.
    6. Run the slide show, enter a response, and click the button.
    7. Confirm that SurveyResponses.csv appears in the configured Documents folder.

    Save the presentation through File → Save As → PowerPoint Macro-Enabled Presentation (*.pptm). A normal .pptx file cannot retain the VBA project.^5^

    If the ActiveX TextBox cannot be inserted or selected

    Microsoft 365 disables ActiveX controls by default. Only change this setting for a presentation whose contents are trusted.^6^

    1. Open File → Options → Trust Center.
    2. Select Trust Center Settings → ActiveX Settings.
    3. Choose Prompt me before enabling all controls with minimal restrictions.
    4. Click OK twice and reopen the presentation.
    5. If a security warning appears, select File → Enable Content → Advanced Options → Enable content for this session.^7^

    This setting applies across supported Office applications, not only this presentation. In a managed business environment, an administrator may enforce a policy that prevents ActiveX from being enabled; if the options are unavailable or locked, the Microsoft 365 administrator must approve an alternative.


    References

    1. Add or register an ActiveX control
    2. Use ActiveX Controls on Slides
    3. Shape object (PowerPoint)
    4. OLEFormat.Object property (PowerPoint)
    5. Saving ppt to pptx or pptm | Microsoft Support
    6. ActiveX controls are disabled by default in Microsoft 365 and Office 2024 | Microsoft Support
    7. Enable or disable ActiveX settings in Office files | Microsoft Support
    AI-generated content may be incorrect. Read our transparency notes for more information.

    Was this answer helpful?

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.