Fill IE forms with data from an Excel sheet

fabcat1

New Member
Joined
May 20, 2022
Messages
17
Office Version
  1. 365
Platform
  1. Windows
Hi,



I’d like to create a macro which would generate entries in a database filling a IE form from an Excel file (1 page for each line of the Excel file)



The steps are :


  1. Declare the variables
    • Dim ws As Worksheet
    • Dim i As Integer
    • Dim lastrow As Integer
    • Dim ie As Object
      Dim objElement As Object
      Dim objCollection As Object
  2. Open the Excel worksheet “Data”
    • Set ws = ThisWorkbook.Sheets("Data")
  3. Open a IE page “mypage”
  4. Temporisation to ensure the page is loaded
    • Do While ie.readyState = 4: DoEvents: Loop
  5. Fill textboxes with the content of the Excel sheet cells ws.Cells(i, 1), ws.Cells(i, 2), ws.Cells(i, 3), ws.Cells(i, 4)
    • Type=”text” id=”textbox1” , Type=”text” id=”textbox2” Type=”text” id=”textbox3” Type=”text” id=”textbox4”
  6. Click the “submit” button
    • Type=”button” id=”submit_button”
  7. Increment i and fill another entry (loop steps 3 to 6)
  8. Loop until ws.Cell(i, 2) is empty


Can someone please help ?

So far the macro opens the IE page
When I try to fill a field nothing happen and I have the following message : "method 'Document' of object IWebBrowser2' failed

When I try to save the form nothing happen and I have the following message : "method 'Document' of object IWebBrowser2' failed


Here is my code so far :

Sub Fill_IE_Form()

Dim ie As Object
Dim objElement As Object
Dim objCollection As Object
Dim ws As Worksheet
Dim i As Integer
Dim lastrow As Integer


' open Excel sheet where the data is stored
Set ws = ThisWorkbook.Sheets("Data")

Set ie = CreateObject("InternetExplorer.Application")

ie.Visible = True
ie.navigate ("https://Path/NewForm.aspx?RootFolder=")
ie.FullScreen = False

'wait until page is loaded + tempo
Do While ie.readyState = 4: DoEvents: Loop ''''Application.Wait Now + TimeValue("00:00:05")


'ie.Document.getElementById("Title_fa564e0f-0c70-4ab9-b863-0177e6ddd247_$TextField").Value = "PPP"

'ie.Document.getElementbyid("TDDemandDesc_6f4f3e35-b3cc-4e25-a2e2-9acd8995bd52_$TextField_inplacerte").Value = "VVV"

'ie.Document.getElementById("SubmitToApprobationButton").Click


Set ie = Nothing
End Sub
 

Excel Facts

Waterfall charts in Excel?
Office 365 customers have access to Waterfall charts since late 2016. They were added to Excel 2019.

Forum statistics

Threads
1,215,811
Messages
6,127,018
Members
449,351
Latest member
Sylvine

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