View Single Post
 
Old 01-11-2012, 07:15 AM
tinfanide tinfanide is offline Windows 7 64bit Office 2010 32bit
Expert
 
Join Date: Aug 2011
Posts: 312
tinfanide is on a distinguished road
Default IE9- "document.getElementsByClassName" problem

Code:
Function w(cName As String, q As String)

On Error Resume Next
Dim IE As New InternetExplorer
IE.Visible = False
IE.navigate "http://hk.dictionary.yahoo.com/dictionary?p=" & q
Do
DoEvents
Loop Until IE.readyState = READYSTATE_COMPLETE
Dim html As HTMLDocument
Set html = IE.document

Dim y As Integer
y = -1

Do Until y > html.getElementsByTagName("div").Length
    y = y + 1
    If html.getElementsByTagName("div")(y).ClassName = cName Then _
      
       w = html.getElementsByTagName("div")(y).innerText
    End If
Loop

IE.Quit
On Error GoTo 0


End Function
Well, I've originally written a set of VBA codes with the use of "document.getElementsByClassName" but it does not work in my users' computers on which they've installed IE9- (mine is IE9)

I thought ClassName only works in IE9 so I tweaked the code above a bit and hoped to have a workaround. It works. It is far from perfect, though.
(Use of "document.getElementsByClassName" can save me work on looping the tags to find where the classname is.

I wonder if there's a direct approach for it. (I can do it in JS but very good in VB)
Reply With Quote