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)