The following setFrameById function's 5th line is showing error "Object does not support property or method".But it is giving the no of frames and showing the frames objects in array .

Error Line: WebBrowser1.Document.frames(i).ID


Dim WithEvents frame_html As MSHTML.HTMLDocument

Private Sub setFrameById(frameId As String)
On Error GoTo 0
Dim i
For i = 0 To (WebBrowser1.Document.frames.Length - 1)
If WebBrowser1.Document.frames(i).ID = frameId Then
Set frame_html = WebBrowser1.Document.frames(i).Document
End If
Next
End Sub