VBA fill in a form in internet explorer

Sense

New Member
Joined
Apr 12, 2018
Messages
6
Hi all,

I am working on a VBA script that automatically fills in a form on a website. Right now I get the following error right after it opens internet: The object invoked has disconnected from its clients.
At my homepc the macro works fine.

Script:
Sub Automate_IE_Load_Page()
'This will load a webpage in IE
Dim i As Long
Dim URL As String
Dim IE As Object
Dim objElement As Object
Dim objCollection As Object
'Create InternetExplorer Object
Set IE = CreateObject("Internetexplorer.application")

'Set IE.Visible = True to make IE visible, or False for IE to run in the background
IE.Visible = True

'Define URL
URL = "spl.dhl.com/smcfs/console/BR2shipment.search"

'Navigate to URL
IE.Navigate URL

' Wait while IE loading...
Do While IE.readyState = 4: DoEvents: Loop
Do Until IE.readyState = 4: DoEvents: Loop <---Error is marked here by the error handler.

Set objCollection = IE.document.getElementsByTagName("input")

i = 0
While i < objCollection.Length
If objCollection(i).Name = "xml:/Shipment/@ShipmentNo" Then

' Set text for search
objCollection(i).Value = "9315"

Else
If objCollection(i).Type = "submit" And _
objCollection(i).Name = "btnSearch" Then

' "Search" button is found
Set objElement = objCollection(i)

End If
End If
i = i + 1
Wend

objElement.Click ' click button to search

'Unload IE
Set IE = Nothing
Set objElement = Nothing
Set objCollection = Nothing

End Sub

What are your thoughts on this why I get the error?

Thanks!
 

Excel Facts

Whats the difference between CONCAT and CONCATENATE?
The newer CONCAT function can reference a range of cells. =CONCATENATE(A1,A2,A3,A4,A5) becomes =CONCAT(A1:A5)
Thanks cerfani,

When I try InternetExplorerMedium I get another error: User-defined type not defined.

Dim IE As SHDocVw.InternetExplorer
Set IE = New InternetExplorerMedium
 
Upvote 0
I had this problem a few days ago, try the code below:

Code:
Dim ie As InternetExplorerMedium


    Set ie = New InternetExplorerMedium
    
    ie.Visible = True
    
    ie.Navigate "your webpage here"
    Application.Wait Now() + #12:00:05 AM#   'may not be needed  in your scenario
    
    Do Until ie.ReadyState = READYSTATE_COMPLETE: Application.Wait Now() + #12:00:01 AM#: Loop
    
    Do
        Set sh = New Shell32.Shell
        For Each eachIE In sh.Windows
            If InStr(1, eachIE.LocationURL, "your webpage here") Then
                Set ie = eachIE
                'IE.Visible = False  'This is here because in some environments, the new process defaults to Visible.
                Exit Do
            End If
        Next eachIE
    Loop
    
    'Rest of your code here...................
 
Upvote 0
Thanks VeryForgetful,
Unfortunately this code doesn't work either. It seems like it cannot work with InternetExplorerMedium.

error: User-defined type not defined.

Do I need something for it to work properly?
 
Upvote 0
You may need one of these
2gx2ts0.jpg
[/IMG]
 
Upvote 0
Right now I get the following error right after it opens internet: The object invoked has disconnected from its clients.
Close all open (visible) IE windows. Open Task Manager and kill (delete) all iexplore.exe processes, if there are any. Then run the macro.

You need the reference to Microsoft Internet Controls for InternetExplorer or InternetExplorerMedium.
 
Upvote 0

Forum statistics

Threads
1,223,911
Messages
6,175,323
Members
452,635
Latest member
laura12345

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