Submitted forms via IE

Mykiej23

New Member
Joined
Jun 2, 2016
Messages
22
Hi all,

I am trying to automate a number of forms we need to submit on a weekly basis with the same details. I have tried writing a VBA code for this however I get an error once i read the first elementbyid.
Code:
Sub SubmitSpark()Dim IE As Object
    Application.ScreenUpdating = False


    Set IE = CreateObject("InternetExplorer.Application")
    IE.Visible = True
    IE.Navigate "Website URL"


    Application.StatusBar = "Submitting"
    ' Wait while IE loading...
    While IE.Busy
        DoEvents
    Wend
    ' **********************************************************************
    IE.document.getElementById("IO:4ae65484353421009f058a23a21d4860").Value = "Test"
    IE.document.getElementById("IO:ac475484353421009f058a23a21d48fb").Value = "test"
    IE.document.getElementById("sys_display.IO:45679484353421009f058a23a21d4821").Value = "Test"
    IE.document.getElementById("submit_button").Click
    '**********************************************************************
    Application.StatusBar = "Form Submitted"
    IE.Quit
    Set IE = Nothing


    Application.ScreenUpdating = True
End Sub

I can't link the URL as this is an internal website. When I inspect the boxes these are the element IDs that I can see.

Any ideas what the issue may be? Any help is appreciated!

Thanks,
Michaela
 

Some videos you may like

Excel Facts

Excel Wisdom
Using a mouse in Excel is the work equivalent of wearing a lanyard when you first get to college

John_w

MrExcel MVP
Joined
Oct 15, 2007
Messages
6,624
Maybe the element of the first getElementById isn't ready or available at that instant. Try replacing that line with
Code:
    Dim elem As Object
    Do
        Set elem = IE.document.getElementById("IO:4ae65484353421009f058a23a21d4860")
        DoEvents
    Loop While elem Is Nothing
    elem.Value = "Test"
 

Mykiej23

New Member
Joined
Jun 2, 2016
Messages
22
Maybe the element of the first getElementById isn't ready or available at that instant. Try replacing that line with
Code:
    Dim elem As Object
    Do
        Set elem = IE.document.getElementById("IO:4ae65484353421009f058a23a21d4860")
        DoEvents
    Loop While elem Is Nothing
    elem.Value = "Test"

Hi,
Thanks for this but doesnt seem to work either. I think the problem is that it is within an iframe looking at the code.
 

John_w

MrExcel MVP
Joined
Oct 15, 2007
Messages
6,624
In that case you need to access the element in the HTMLdocument within the iframe. I recommented setting a reference to MS HTML Object library and then you declare variables with the appropriate HTML data type and see their methods and properties with intellisense editing. Try something like this - there are other examples on this forum - however I can't really help much more.
Code:
    Dim HTMLdoc As HTMLDocument
    Dim frame As HTMLIFrame
    Set HTMLdoc = IE.document
    Set frame = HTMLdoc.getElementById("iframe id")   'or getElementsByName("iframe name")(0), or getElementsbyTagName("IFRAME")(0)
    Set HTMLdoc = frame.contentDocument
    Do
        Set elem = HTMLdoc.getElementById("IO:4ae65484353421009f058a23a21d4860")
        DoEvents
    Loop While elem Is Nothing
    elem.Value = "Test"
 

Watch MrExcel Video

Forum statistics

Threads
1,123,400
Messages
5,601,462
Members
414,451
Latest member
jrose7

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Top