Excel VBA 提交 Microsoft 表单

Excel VBA submit a Microsoft Form

我正在尝试提交一个包含来自 VBA 脚本的一些值的 Microsoft 表单,这样当一天中发生特定的事情时,我可以立即查看所有事件。我已经在IE中打开,将值放入框中,然后提交,但值似乎没有保存。

我想知道在设置问题值时我是否可以做一些不同的事情

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

当我使用自己的 Microsoft Form 进行测试时,我可以重现该问题。 question.value 好像不能给输入框有效的设置值。在这种情况下,您可以使用SendKeys模拟用户输入,为输入框设置值。

你可以把设置问题值的代码块改成下面这样,我测试过可以正确设置和保存值:

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")