I'm trying to submit a Microsoft Form with some values from a VBA script so that when something specific happens throughout the day, I can view all occurrences at once. I've got it opening up in IE, putting the value in the box, and then submitting, but the value does not seem to save.
I'm wondering if there is something different I can do when setting the questions value
Sub Init_app3()
Dim IE As InternetExplorer
Dim URL As String
Dim question As Object
Dim btnGo As Object
Set IE = CreateObject("InternetExplorer.Application")
IE.Visible = True
URL = "https://forms.office.com/r/mvT5hD1RRT"
IE.navigate (URL)
Do
DoEvents
Loop Until IE.readyState = 4
Set question = IE.document.getElementsByClassName("office-form-question-textbox office-form-textfield-input form-control office-form-theme-focus-border border-no-radius")(0)
With question
.value = "MALE"
End With
Set btnGo = IE.document.getElementsByClassName("button-content")(0)
delay 5
With btnGo
.Click
End With
delay 5
IE.Quit
Set IE = Nothing
Exit Sub
End Sub
CodePudding user response:
I can reproduce the issue when I test with my own Microsoft Form. It seems that question.value
can't set a value to the input box effectively. In this situation, you can simulate user input using SendKeys
to set value to the input box.
You can change the block of code setting question value into the following, I have tested it and it can set and save the value correctly:
Set question = IE.document.getElementsByClassName("office-form-question-textbox office-form-textfield-input form-control office-form-theme-focus-border border-no-radius")(0)
question.Focus
SendKeys ("MALE")