PDA

View Full Version : IE Automation



jigar1276
05-13-2016, 03:45 AM
Dear Experts,
I am working on some automation wherein data will be in excel and need to update the fields in website using excel values.
I found this macro online and tried to edit it, but its not working.
Please advice so I can proceed further with updation of fields once login is succesful.

I have added following referances:
Microsoft HTML Object Library
Microsoft Internet controls

Questions: Tried running it in IE8. Do I need to update to IE 11?

Received error: Method 'Document' of object 'IWebBrowser2' failed on line


IE.document.getelementsbyname("_58_login").Value = "jigarjigar"

Macro is as follow:


Public Declare PtrSafe Function SetForegroundWindow Lib "user32" (ByVal HWND As Long) As Long

Sub Automate_IE_Enter_Data()
'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
Dim HWNDSrc As Long
Dim document As HTMLDocument

'Create InternetExplorer Object
Set IE = GetObject("new:{D5E8041D-920F-45e9-B8FB-B1DEB82C6E5E}")
'Set IE = CreateObject("InternetExplorer.Application")

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

'Navigate to URL
IE.Navigate https://www.asite.com/login-home/
' Wait while IE loading...
Do While IE.ReadyState = 4: DoEvents: Loop

'Get Window ID for IE so we can set it as activate window
HWNDSrc = IE.HWND

'Set IE as Active Window
SetForegroundWindow HWNDSrc

'Find & Fill Out Input Box

IE.document.getelementsbyname("_58_login").Value = "jigarjigar"
IE.document.getelementsbyname("_58_password").Value = "mypassword"
IE.document.getelementsbyclassname("btn-submit nobgcolor").Click
'Unload IE
endmacro:
Set IE = Nothing
Set objElement = Nothing
Set objCollection = Nothing

End Sub