VBA 提交 MS 表单:输入值已填写但未成功提交
VBA submit MS Form: input value has been filled but not successfully submited
我正在 excel 中使用 VBA 提交 MS 表单。它可以将值填充到文本输入中,但提交后,这个问题仍然是空白。有什么想法吗?
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
提交前,值已填写正确
这个 <div class="button-content">Absenden</div>
不是按钮,但实际按钮以 <button
开头,所以这就是您需要查找并点击的按钮。
<button class="office-form-theme-primary-background office-form-theme-button office-form-bottom-button button-control light-background-button __submit-button__" title="Absenden" role="button">
<div class="button-content">Absenden</div>
</button>
为了点击发送按钮,您可以使用类似
的东西
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
使用
设置文本框的值后
IE.document.getElementsByClassName("office-form-question-textbox office-form-textfield-input form-control office-form-theme-focus-border border-no-radius")(0).Value = "currentUserEmailAddress"
我以前遇到过这种问题。也可以参考.
问题的根本原因是.Value
无法有效地设置值。在这种情况下,您可以使用SendKeys
模拟用户输入,将值设置到输入框。
示例代码:
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")
我正在 excel 中使用 VBA 提交 MS 表单。它可以将值填充到文本输入中,但提交后,这个问题仍然是空白。有什么想法吗?
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
提交前,值已填写正确
这个 <div class="button-content">Absenden</div>
不是按钮,但实际按钮以 <button
开头,所以这就是您需要查找并点击的按钮。
<button class="office-form-theme-primary-background office-form-theme-button office-form-bottom-button button-control light-background-button __submit-button__" title="Absenden" role="button">
<div class="button-content">Absenden</div>
</button>
为了点击发送按钮,您可以使用类似
的东西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
使用
设置文本框的值后IE.document.getElementsByClassName("office-form-question-textbox office-form-textfield-input form-control office-form-theme-focus-border border-no-radius")(0).Value = "currentUserEmailAddress"
我以前遇到过这种问题。也可以参考
问题的根本原因是.Value
无法有效地设置值。在这种情况下,您可以使用SendKeys
模拟用户输入,将值设置到输入框。
示例代码:
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")