• Hi All

    Please note that at the Chandoo.org Forums there is Zero Tolerance to Spam

    Post Spam and you Will Be Deleted as a User

    Hui...

  • When starting a new post, to receive a quicker and more targeted answer, Please include a sample file in the initial post.

Excel and IE automation

Jigar B

New Member
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

Changed: I have updated to IE11 and now the error is changed to "Automation error, unspecified error"

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

Code:
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 [URL]https://www.asite.com/login-home/[/URL]
    ' 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
 

Attachments

  • 1 - WebForm filling - Eliments.xlsm
    16.1 KB · Views: 12
Last edited:
Thanks for the reply, Chihiro.

I tried the method but its giving me error. Automation Error, unspecified error.
 
Last edited:
its giving error:
Automation Error, Unspecified Error at line
IE.document.getElementsByName("_58_login")(0).Value = "jigarjigar"
 
Then I'm guessing that login string needs to be modified. You may also want to contact Site Administration to obtain documentation (if available) on their API and/or Web Services.
 
Hi,
I have an trick to overcome this error.

Close all instances of 'Explorer' using Task manager and then try to run the code, it will work.

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

Changed: I have updated to IE11 and now the error is changed to "Automation error, unspecified error"

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

Code:
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 [URL]https://www.asite.com/login-home/[/URL]
    ' 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
 
Back
Top