Microsoft
Software
Hardware
Network
Question : Readystate in IE in VBA program
Dear Expert,
Lots poeple will use following VBA code to navigate the wbesite in IE, and I found some unstable issue or error
in my code that means sometimes it work ok but sometimes is not working, I have used "Debug.print" to
check where is error, found at Code-line-11, .document.all("login").cli
ck has issue with Readystate
we use .navigate to grab the website in first time , Readystate and Busy state of IE will be good flag to see
the IE ready and busy or not. So checkreadystate function is okay for first time to explore IE. But When I use .doucment.all("Login").cli
ck to change to second other website page, it seems Readystate and Checkreadystate function desn't help much for waiting/monitor "login" page is ready and busy or not. I guess the is because Readystate is already set by first time to nagviate "
http://example.com
" if successfully at(code-line-7) And the user could not change the state of REadystate except quit the IIE windows. So, I try to put put code-line-13, adding Sleep(3000) for 3 seconds delay, the VBA code works fine. And sometime we also put back code-line-6 make it .Visible IE windows, it also work but not all the times. It seems the issue and error is not stable at all that might be related to timming of loading the "Login" page. Is there any method to check When the second time of loading page is ready and busy or not but be reminded it is second time loading page after nagviate the first page
I mean first time of loading page, for example, first time to navigate IE explorer and seoncd time loading page
means you have to base on the first page is ready in order to access the second website, Just similar to
when you login your bank website.
I don't want to use Sleep(3000) function and .Visible to let second loading page is ready first before we are
running our rest of our program code.
What is suggestion to solve this issue
? If you understand my issue, please let me know. I will explain more. Please advise
Br
Duncan
1-Dim myIE As SHDocVw.InternetExplorer 'Need Microsoft Internet Controls reference selected
2-Set myIE = Nothing
3-Set myIE = CreateObject("InternetExpl
orer.Appli
cation")
4-Set myIE = New InternetExplorer
5-With myIE
6- '.Visible = True
7- .navigate "
https:example.com
"
8-Call CheckREadyState(myIE, 1)
9- .doucment.all("username")=
"ABC"
10-.doucment.all("password
")="33443"
11-.doucment.all(login).cl
ick
12-Call CheckREadyState(myIE, 1)
13-'Sleep(3000)
Function CheckReadystate(ByRef myIE As Object, state1 As Integer)
With myIE
Do Until Not .Busy And .readyState = READYSTATE_COMPLETE
Debug.Print state1
Debug.Print .Busy
Debug.Print .readyState
DoEvents
Loop
End With
End Function
Answer : Readystate in IE in VBA program
Whoops.. Changed code to reflect decleration (MyIE)
1: 2: 3: 4:
' Wait for the page to load. Do While myIE.Busy Or myIE.ReadyState <> 4 DoEvents Loop
Random Solutions
Infering View Definition
iPhone, how do I correctly pass data model object data between various view controllers without breaking MVC?
Error: SQLSTATE[24000]: Invalid cursor state
VSS Snapshot warning. File c:\windows\system32\vmbusp
ipe.dll is not present
Outlook stationery, multiple BCC recipients, spam filters
open window fitting an image
Indesign CS5 overset text problem
Deleting Windows directory on secondary installation
read pdf from blob column write to file
Error when saving a date in MS SQL...