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
 

Excel Facts

What does custom number format of ;;; mean?
Three semi-colons will hide the value in the cell. Although most people use white font instead.
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"
 
Upvote 0
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.
 
Upvote 0
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"
 
Upvote 0

Forum statistics

Threads
1,214,653
Messages
6,120,749
Members
448,989
Latest member
mariah3

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
Back
Top