VBA to Enter Data Online and Submit Form

…衆ロ難τιáo~ 提交于 2020-01-27 08:15:38

问题


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.

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

回答1:


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


来源:https://stackoverflow.com/questions/17409613/vba-to-enter-data-online-and-submit-form

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!