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
Table Partitioning
Centering text in header of collapsible panel
DNS Zones not AXFR'ing from primary
Quantum DLT V4 Tape Drive ejects cartridge straight after inserting it
div height worls in everything else but IE? WHY?
phase difference of trig functions
layering DIVs with Flash and HTML content
ie8 img border transparent gif bug
A new install of Windows 7 Ultimate network PCs See Me I do not see them File print sharing enabled and there are admins that match on every machine
Where is the "iPhone Simulator" folder located?