• 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.

Trouble with Excel Macro Auto Login

techmikeprog

New Member
There is some great information on this web site however I haven't found a solution yet. I have been trying to use a Macro in VBA/Microsoft Excel to auto login to a web site automatically and fill in information into the web page. On the up side I'm able to do this on several different web sites (google, hotmail, etc); however, when I attempt to log in to a couple in particular web sites I receive an error. The message reads:

"System Error &H80010108 (-2147417848). The object invoked has disconnected from its client."


Again, I know the code is close to correct because this works on several web pages, but a couple others time out. After several days of researching I'm still not any closer to a solution. When running the code line-by-line, it appears as though VBA/Excel is loosing the webpage. I'm not sure if it's because the web site is encrypted or something else may be going on.

I've attached the code below and commented where the problem is. Do you have any thoughts why I may be having issues with this web site? Any thoughts would be greatly appreciated!!!

-Thanks


*****VBA SCRIPT*****

Code:
Sub WebPageStartup()

Dim IE As Object

Set IE = CreateObject("InternetExplorer.Application")
IE.Visible = True

IE.navigate "https://enterpriseportal.disney.com"

Do                         '-Begins the problem when waiting for ready state to be complete
DoEvents
Loop Until IE.readyState = 4

HTMLDoc.all.USER.Value = "abc"
HTMLDoc.all.PASSWORD.Value = "123"
IE.document.getElementById("Enter").Click

End Sub
 

techmikeprog

New Member
Yes. Seems to be no change adding ". Also added "Option Explicit", and "On Error GoTo Err_Clear" which will pass over the error, but will prevent the ability to to the beginning of the code with no change. Again it does work for every other website I've tried like google.com, hotmail.com, etc, but for some reason will not work with this particular web site. This makes me think the code is all correct. Something about this page it does not like? I'm sure there is an answer..?
 

Marc L

Excel Ninja

Very bad code - can't work whatever the website - and not loosing anything,
just because HTMLDoc is not declared and worst it is empty !
With a pair of neurons, just replace it by IE.Document
As Copy / Paste is very not coding ! :rolleyes:
 

techmikeprog

New Member
Thank you so much for reaching out. I am so sorry for overlooking this. You are correct. "HTMLDoc" was not declared that should read "IE" which was declared. (I tried making this change but I was still receiving the same error.)

I decided to try another way of coding it to see everything stepping through and get feedback.

Running this code 1 line at a time (pressing F8) through this new code below, everything works correctly until
Code:
Loop Until MyBrowser.readyState = READYSTATE_COMPLETE
with the enterpriseportal web site listed in the code. If I change this code to www.google.com everything works just fine so I do not believe it is the code. Is there a reason why it may not be passing this through correctly? I have also attached a few photos to show the errors.

Any additional support would be greatly appreciated!!




**Using the following code "MyBrowser.readyState" returns an error. "Automation Error"




** "READYSTATE_COMPLETE" shows it equals 4.





Code:
Sub MyGmail()

Dim HTMLDoc As HTMLDocument
Dim MyBrowser As InternetExplorer
Dim MyHTML_Element As IHTMLElement
Dim MyURL As String
On Error GoTo Err_Clear

'-MyURL = "https://www.google.com"  '<<Lined out but when used in place of enterprise web site, all other code works with no errors>>
MyURL = "enterpriseportal.disney.com"
Set MyBrowser = New InternetExplorer
MyBrowser.navigate MyURL
MyBrowser.Visible = True

Do
Loop Until MyBrowser.readyState = READYSTATE_COMPLETE

Set HTMLDoc = MyBrowser.document
HTMLDoc.all.Text.Value = "name@email.com"
HTMLDoc.all.Password.Value = "123"

Err_Clear:
If Err <> 0 Then
Err.Clear
Resume Next
End If

End Sub
 

Marc L

Excel Ninja

Again a code not very …

Like in your previous code, try DoEvents statement within the Do Loop
 
Top