Hi tinfanide,
I'm not familiar with IE automation. However, when I test your funnction with:
Code:
Sub Test()
GetElementsByClassName1 "pronunciation", "dog"
End Sub
it fails every time at 'Set html = IE.Document' with the error message "Runtime Error '2147467259 (80004005)': / Automation Error / Unspecified Error". You can fix that by moving the
'Set html = IE.Document' after the 'Loop' line. Speaking of which your 'Do Until ... Loop' should have a 'DoEvents' statement, like:
Code:
Do Until IE.readyState = READYSTATE_COMPLETE
DoEvents
Loop
After moving the 'Set html = IE.Document' line, the code runs to completion OK, but there is still no sound - which is what I gather you're intending to get.
Your code would also be more efficient with:
Code:
Result = Array(0)
For Each tag In tags
If tag.className = cName Then
Set Result(0) = tag
Exit For
End If
Next tag
GetElementsByClassName1 = Result(0).getElementsByTagName("div")(0).innerText
and even moreso if you dispense with the array:
Code:
For Each tag In tags
If tag.className = cName Then
GetElementsByClassName1 = tag.getElementsByTagName("div")(0).innerText
Exit For
End If
Next tag
None of which resolves the underlying problem, but might help with the project overall.
PS: I'm moving the thread to the Excel forum, as you've posted in the
Word vba forum and your attachment shows this is really for Excel.