I need help with automating form submissions using Excel VBA
I’m working on an Excel add-in that needs to send data to a Google Form automatically when users click a button. The goal is to track feature usage in my application.
I’ve been trying to use Internet Explorer automation but I’m running into issues. Here’s my current approach:
Sub SubmitToGoogleForm()
Dim browser As Object
Set browser = CreateObject("InternetExplorer.Application")
On Error GoTo ErrorHandler
With browser
.navigate "https://forms.google.com/my-form-url"
Do While .busy: DoEvents: Loop
Do While .ReadyState <> 4: DoEvents: Loop
With .document.Forms(0)
.getElementById("entry_123").Value = Application.UserName
.getElementById("entry_456").Value = "feature_data"
.submit
End With
End With
Exit Sub
ErrorHandler:
browser.Quit
Set browser = Nothing
End Sub
The main problem I’m facing is that the form elements aren’t being found correctly. I’m getting errors when trying to access the input fields.
Has anyone successfully automated Google Forms with VBA? Are there alternative approaches I should consider for collecting usage analytics from an Excel add-in?
Yeah, Internet Explorer won’t work well here - Google Forms needs JavaScript to render and submit properly. I hit the same wall when automating form submissions for data collection. What saved me was ditching browser automation entirely and using WinHTTP instead. Just open your browser’s developer tools, submit the form manually, and capture the actual HTTP request it sends. Then replicate that exact request in VBA with WinHTTP.Request. You’ll skip all the JavaScript headaches and DOM issues completely. Just heads up - Google Forms might have CSRF protection and rate limiting, so you may need to handle those. For usage analytics though, I’d honestly just write to a text file or database instead. Automated form submissions can be flaky and might break their terms of service anyway.
Google Forms automation with VBA is a pain - super unreliable these days. I’ve had way better results using webhooks or writing straight to Google Sheets through their API. The form parsing breaks constantly since they keep changing the HTML structure. You might want to just log everything locally first, then batch upload it all at once.
I had the same issues with Google Forms automation in VBA. The problem is Google Forms uses dynamic element IDs and loads everything with JavaScript, so traditional DOM manipulation just doesn’t work reliably. Instead of wrestling with Internet Explorer automation, I switched to XMLHttpRequest and POST data directly to the form’s action URL. Just open your browser’s developer tools and check the network traffic to see what POST parameters Google Forms expects. This skips all the HTML element interaction and works way better. Fair warning though - Google’s been cracking down on automated submissions lately. You might want to try a simple web service instead or use the Google Sheets API for your usage analytics.