8

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
Community
  • 1
  • 1
Steve Rynearson
  • 81
  • 1
  • 1
  • 2
  • That page is totally broken in IE8 – Tim Williams Jul 01 '13 at 16:57
  • Can you enter data/submit? That's the only purpose of this webpage. – Steve Rynearson Jul 01 '13 at 17:29
  • All I see is a dozen unlabelled textboxes and a "submit" button. Looking at the HTML though, you'd be better off trying to populate the textboxes based on their names (appear to be constant) than their Id's (which appear to have a changing numeric suffix) – Tim Williams Jul 01 '13 at 17:52
  • Good catch on the changing IDs. I assumed the numeric portion was static. Per this thread it looks like using getelementsbyname may actually want to look for id?: http://stackoverflow.com/questions/14575671/on-ie-document-getelementsbyname-wont-work . I will try changing some of the html coding. – Steve Rynearson Jul 01 '13 at 18:31
  • `IE.Document.formNameHere.inputNameHere.Value` should work. – Tim Williams Jul 01 '13 at 18:51

1 Answers1

5

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
Santosh
  • 12,175
  • 4
  • 41
  • 72
  • I used a different set up for the forms and got everything to work perfectly. Thanks for the suggestione veryone. – Steve Rynearson Jul 04 '13 at 00:52
  • I am using the same code. At the end it clicks a button to navigate to a new page.Once that is done I cant access elements of the new page.What could I be missing. – Richa Aug 21 '15 at 06:46
  • @Richa You should make sure that your page has finished loading. I created a simple sub to help accomplish this: `Sub IEBusy(IE_Object As Object)` `Do While IE_Object.Busy or IE_Object.ReadyState <> 4` `DoEvents` `Loop` `Exit Sub`. You just then use `Call IEBusy(IE)` and it's that simple to wait for the page to finish loading. – K.Dᴀᴠɪs Jun 20 '17 at 22:23