vba VBA在线输入数据并提交表格

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/17409613/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-08 16:00:43  来源:igfitidea点击:

VBA to Enter Data Online and Submit Form

vbaexcel-vbaexcel

提问by Steve Rynearson

I'm trying to use VBA to submit data from Excel to a webform online. The issue happens within the *area where I'm trying to select and update the form. I've tried a variety of options (getelement by ID, name, etc.) without any success. I believe the issue has to do with identifying the appropriate element. I've seen advice about using the Locals feature in VBA, but I'm not sure how to use that for this purpose. I have a feeling someone with some experience could figure this out very quickly by looking at the source code on the webiste, using Locals in VBA, or some other technique.

我正在尝试使用 VBA 将数据从 Excel 提交到在线网络表单。问题发生在我尝试选择和更新表单的*区域内。我尝试了各种选项(通过 ID、名称等获取元素),但都没有成功。我认为这个问题与确定适当的元素有关。我看过有关在 VBA 中使用 Locals 功能的建议,但我不确定如何为此目的使用它。我有一种感觉,有经验的人可以通过查看网站上的源代码、在 VBA 中使用 Locals 或其他一些技术来很快解决这个问题。

The form is set up so all fields are text and I can enter/submit data online with no problem.

表单已设置,因此所有字段都是文本,我可以毫无问题地在线输入/提交数据。

Thanks in advance for any help/suggestions.

提前感谢您的任何帮助/建议。

Dim IE As Object

Sub submitFeedback3()
Application.ScreenUpdating = False

Set IE = CreateObject("InternetExplorer.Application")
IE.Visible = True
IE.Navigate "http://spreadsheetbootcamp.com/excel-efficiency-trainer-feedback/"

Application.StatusBar = "Submitting"
  ' Wait while IE loading...
 While IE.Busy
 DoEvents
 Wend
 **********************************************************************
 IE.Document.getElementById("Form_Attempts-1372643500")(0).Value = "1"
 IE.Document.getElementById("submit-1-1372643500")(0).Click
 **********************************************************************
 Application.StatusBar = "Form Submitted"
 IE.Quit
 Set IE = Nothing

Application.ScreenUpdating = True
End Sub

回答by Santosh

Try below code

试试下面的代码

Dim IE As Object

Sub submitFeedback3()
    Application.ScreenUpdating = False

    Set IE = CreateObject("InternetExplorer.Application")
    IE.Visible = True
    IE.Navigate "http://spreadsheetbootcamp.com/excel-efficiency-trainer-feedback/"

    Application.StatusBar = "Submitting"
    ' Wait while IE loading...
    While IE.Busy
        DoEvents
    Wend
    ' **********************************************************************
    delay 5
    IE.Document.getElementById("experience-1372700847").Value = "ddddd1"
    delay 5
    IE.Document.getElementById("Form_Time_Best-1372700847").Value = "ddddddddddd2"
    delay 5
    IE.Document.getElementById("submit-1-1372700847").Click
    '**********************************************************************
    Application.StatusBar = "Form Submitted"
    IE.Quit
    Set IE = Nothing

    Application.ScreenUpdating = True
End Sub

Private Sub delay(seconds As Long)
    Dim endTime As Date
    endTime = DateAdd("s", seconds, Now())
    Do While Now() < endTime
        DoEvents
    Loop
End Sub