Home > Enterprise >  VBA submit MS Form: input value has been filled but not successfully submited
VBA submit MS Form: input value has been filled but not successfully submited

Time:03-22

I am using VBA in excel to submit a MS form. It could fill the values to text inputs but after submit, this question is still blank. Any thoughts?

Dim emailDomain As Variant
Dim URL As String        
        Set IE = GetObject("new:{D5E8041D-920F-45e9-B8FB-B1DEB82C6E5E}")
        IE.Visible = True
        URL = "https://forms.office.com/Pages/ResponsePage.aspx?id=Aq5v9jZdW0m_4Him_5-ObrQJR7r8UGdPhwKFE494ioxUOEg4M1Q5STRGSzk5Q1VPMTJPRUNLMk5IMi4u"
        IE.navigate (URL)

        While IE.Busy
        DoEvents
        Wend             
        
        IE.document.getElementsByClassName("office-form-question-textbox office-form-textfield-input form-control office-form-theme-focus-border border-no-radius")(0).Value = "currentUserEmailAddress"

        delay 5
        IE.document.getElementsByClassName("button-content")(0).Click
        IE.Quit
        Set IE = Nothing

End Sub

Before submit, the value has been filled correctly

enter image description here

CodePudding user response:

This <div >Absenden</div> is not a button but the actual button starts with <button so this is what you need to look for and click on.

<button  title="Absenden" role="button">
    <div >Absenden</div>
</button>

In order to click the send button you can use something like

IE.document.getElementsByClassName("office-form-theme-primary-background office-form-theme-button office-form-bottom-button button-control light-background-button __submit-button__")(0).Click

after you have set the value of the textbox with

IE.document.getElementsByClassName("office-form-question-textbox office-form-textfield-input form-control office-form-theme-focus-border border-no-radius")(0).Value = "currentUserEmailAddress"

enter image description here

CodePudding user response:

I met this kind of issue before. You can also refer to this thread.

The root cause of the issue is .Value can't set the value effectively. In this situation, you can simulate user input using SendKeys to set value to the input box.

Sample code:

IE.document.getElementsByClassName("office-form-question-textbox office-form-textfield-input form-control office-form-theme-focus-border border-no-radius")(0).Focus
SendKeys ("currentUserEmailAddress")
  • Related