* i am sorry if i post this twice. something happen and i can't find my first post after i posted *

Hello,
I am pretty new at VBA and still try to learn. I inherit this VBA code at work from previous employee that is no longer with the department. The code work most of the time but at time it randomly just stop/break. I have been trying to find a fix for the past 2 weeks and have not luck. Can someone please help.

i've have tried several thing but have no luck.

do i need to declare some of the value in order for it to work all the time?


Please see the code below:
===========================================================================================================================
Private Sub Test(ByRef myie As SHDocVw.InternetExplorer)
Set iedoc = myie.Document
Dim Fill As HTMLTableCell


QMSI = False

Call NextScreen(myie)
While myie.busy
DoEvents
Wend

' I tried to replace the above "While myie.busy - DoEvents - Wend" with While myie.busy Or myie.readystate <> 4: DoEvents: Wend this but no good
' I even tried put a Do While loop "Do - Set FillHistory = iedoc.getElementsByName("fill_seg") - While iedoc.getElementsByName("fill_seg") <> 0" but also no good

' the code break here (per debug.print) right before the Set statement.
'Do I need to delcare "FillHistory" As HtmlElementCollection and "lookqmis" as String or something else?

Set FillHistory = iedoc.getElementsByName("fill_seg")
' I place a debug.print for FillHistory here and nothing happen only a blank when the code break

For Each Fill In FillHistory(0)

lookqmis = Fill.innerText
If InStr(1, lookqmsi, "open") <> 0 Then
'my routine
QMSI = True
End If
Next

End Sub
==========================================================================

thank you for your help.