View Single Post
 
Old 01-13-2012, 12:43 AM
macropod's Avatar
macropod macropod is offline Windows 7 64bit Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,963
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

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.
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote