How to automatically populate and send Google Forms using VBA in Excel

I need assistance with crafting a VBA script that can automatically fill out and submit a Google Form whenever a button is pressed in my Excel add-in. My aim is to monitor which features the users are engaging with in my program.

Here’s the HTML setup of the form field I’m focusing on:

<div class="form-container">
    <div class="question-item required text-field">
        <div class="form-entry">
            <label for="field_1" class="question-title">
                Employee ID
                <span class="required-mark">*</span>
            </label>
            <input type="text" 
                   id="field_1" 
                   class="input-short" 
                   value="" 
                   name="field.1.response">
        </div>
    </div>
</div>

I tried this method, but I’m running into an error when attempting to set the field value:

Sub SubmitDataToForm()
    Dim browser As Object
    Set browser = CreateObject("InternetExplorer.Application")
    
    On Error GoTo cleanup
    
    With browser
        .navigate "https://forms.google.com/myformurl"
        
        Do While .busy: DoEvents: Loop
        Do While .ReadyState <> 4: DoEvents: Loop
        
        With .document.Forms(0)
            .EmployeeID.Value = Application.UserName
            .Department.Value = "IT-Support"
            .submit
        End With
        
        Do While .busy: DoEvents: Loop
        MsgBox "Form submitted successfully"
    End With
    
cleanup:
    browser.Quit
    Set browser = Nothing
End Sub

The error occurs on the line where I try to assign the employee ID value. I suspect the problem is that VBA is unable to locate the form element by its name. Any advice on how to correctly reference form fields or explore alternative solutions would be appreciated.

google forms with vba is just a pain these days. your code looks okay, but google keeps changin security stuff that messes up automation. try switching to selenium webdriver instead of using the ie object. it’s way more reliable for modern sites. also, add some sleep timers between actions since google forms load things async, so ur script might be running too fast.

I’ve hit this same issue with VBA and Google Forms. The problem is you’re not targeting the form elements correctly. Google Forms don’t use standard field names like “EmployeeID” - they use specific identifiers instead. Looking at your HTML, you need to target “field.1.response”. Try this: .document.getElementsByName(“field.1.response”)(0).Value = Application.UserName. But heads up - Google’s been making their forms way harder to automate lately. They’re using dynamic loading and anti-bot stuff that breaks traditional web scraping. I’ve had better luck using Google Apps Script or their Forms API. You might want to create a simple web app script that takes POST requests from your Excel code instead of wrestling with the form interface directly.

I’ve dealt with this exact issue when automating Excel form tracking. Try using getElementById since you already have the field ID from the HTML: browser.document.getElementById(“field_1”).Value = Application.UserName instead of the form reference approach. You’re missing wait conditions after navigation - Google Forms takes forever to load everything. I always check if the element actually exists before trying to fill it: If Not browser.document.getElementById(“field_1”) Is Nothing Then… Google Forms timing is a nightmare. What worked better for me was ditching browser automation completely and using XMLHttpRequest to POST directly to the form endpoint. Just capture the POST request in dev tools and recreate it in VBA.

This topic was automatically closed 4 days after the last reply. New replies are no longer allowed.