Here is an example of the problem I have. The attached spreadsheet has a button that when clicked will open a website that has an example of a RadWindow, which is a window within a window. It will read the value of an element on the parent window, which in this case is "POST", and display it in a message box. Then it will attempt to read and display the value of an element from the RadWindow (Child Window), and this is where I get an error. I can't figure out how to access the Child Window rather than the Parent.
Here is the code, if you would rather create a new workbook from scratch:
'Microsoft Internet Controls Reference is needed
'Microsoft HTML Object Library Reference is needed
Public Sub ReadNotes()
Dim objShellWins As SHDocVw.ShellWindows
Dim objIE As SHDocVw.InternetExplorer
Dim objDoc As Object
Dim WebCheck As String
Dim SuccessCheck As Integer
Dim URL1 As String
'Demonstration Webpage URL and checks to make sure webpage is open
URL1 = "http://demos.telerik.com/aspnet-ajax/window/examples/overview/defaultcs.aspx"
WebCheck = "ASP.NET Window Demo"
SuccessCheck = 0
'Open new webpage and navigate to webpage
Set objIE = New SHDocVw.InternetExplorer
objIE.navigate URL1
'Wait until internet explorer is done loading before proceeding
Call ExplorerStatusCheck(objIE)
'Check each open tab for the webpage
Set objShellWins = New SHDocVw.ShellWindows
For Each objIE In objShellWins
With objIE
If (InStr(1, .LocationName, WebCheck, vbTextCompare)) Then
Set objDoc = .document
If (TypeOf objDoc Is HTMLDocument) Then
SuccessCheck = 1
objIE.Visible = True
'-----------This section of code will read the element from the Parent window and display its value, "POST"----
Set objNotes1 = objIE.document.getElementsByName("ctl00$RatingAndReview$SubmitComment")
objNotes1 = objNotes1(0).Value
MsgBox objNotes1
'-----------This is the section of code I am having problems with, I don't know how to get the value of an element in
'-----------a child window. I think the problem is that it is looking for the element in the Parent window.
Set objNotes2 = objIE.document.getElementsByName("ctl00$ProductSearch2$tbInMenuSearchBox$emptyTextInput")
objNotes2 = objNotes2(0).Value
MsgBox objNotes2
Exit For
'------------------------------------------------------------------------------------------------------------------
End If
End If
End With
Next
'If the webpage is not found, displays an error message
If SuccessCheck = 0 Then
MsgBox ("Webpage not found." & vbCrLf & vbCrLf _
& "Please try again."), vbCritical
End If
End Sub
'Wait until internet explorer is done loading before proceeding
Public Sub ExplorerStatusCheck(objIE As SHDocVw.InternetExplorer)
With objIE
Do While .Busy: DoEvents: Loop
Do While .readyState <> 4: DoEvents: Loop
Do Until .Busy = False
Loop
While objIE.readyState <> READYSTATE_COMPLETE
DoEvents
Wend
End With
End Sub
Thanks,
Matt
Bookmarks