![]() |
|
#1
|
||||
|
||||
![]()
Hi tinfanide,
The document.getElementsByClassName parameter is available in IE9 / HTML5. So, if it's not working on your users' PCs, it would seem that either their IE9 installation is faulty or they don't actually have IE9 installed.
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
#2
|
|||
|
|||
![]() Quote:
Code:
Option Explicit Function GetElementsByClassName1(cName As String, q As String) Dim IE As New InternetExplorer IE.Visible = True IE.navigate "http://hk.dictionary.yahoo.com/dictionary?p=" & q Dim html As HTMLDocument Set html = IE.Document Do Until IE.readyState = 4 Loop Dim Result Dim tag Dim tags As Object Set tags = html.getElementsByTagName("*") Result = Array() For Each tag In tags If tag.className = cName Then ReDim Preserve Result(UBound(Result) + 1) Set Result(UBound(Result)) = tag End If Next tag GetElementsByClassName1 = Result(0).getElementsByTagName("div")(0).innerText IE.Quit End Function Could ya please debug the code for me? It seems that I cannot pass the arguments directly "strings" (with reference to the error help in Excel) It's beyond what I know about VBA. |
#3
|
|||
|
|||
![]()
Well, I've made another try and the result was more weird.
GetElementsByClassName.xlsm If I debug it in VBA Editor, it returns the results in each cell. But when I run it as a macro, it does not return any value. |
#4
|
|||
|
|||
![]()
Just fix it.
Code:
Sub WebDictQuery() Dim x As Integer Dim Query As String For x = 1 To 3 Cells(x, 3).Value = GetElementsByClassName("pronunciation", Cells(x, 1).Value) Next x End Sub Function GetElementsByClassName(className, q) '''''''''''''''''''''''''''''''''''''''' Dim IE As Object Set IE = CreateObject("InternetExplorer.Application") '''''''''''''''''''''''''''''''''''''''' IE.Visible = False IE.navigate "http://hk.dictionary.yahoo.com/dictionary?p=" & q Do Until IE.readyState = 4 Loop Dim Result Dim tag Dim tags As Object ''''''''''''''''''''''''''''''''''''''''''''''''''' Set tags = IE.document.getElementsByTagName("*") ''''''''''''''''''''''''''''''''''''''''''''''''''' Result = Array() For Each tag In tags If tag.className = className Then ReDim Preserve Result(UBound(Result) + 1) Set Result(UBound(Result)) = tag End If Next tag GetElementsByClassName = Result(0).getElementsByTagName("div")(0).innerText IE.Quit '''''''''''''''''''''''''''''''''''' Set IE = Nothing '''''''''''''''''''''''''''''''''''' End Function Code:
Set html = IE.Document |
![]() |
|
![]() |
||||
Thread | Thread Starter | Forum | Replies | Last Post |
How to edit the "Format" and the "show level" of an EXISTING table of content? | Jamal NUMAN | Word | 2 | 08-14-2011 10:46 AM |
![]() |
lisa801 | Word | 3 | 07-08-2011 10:11 PM |
![]() |
Jamal NUMAN | Word | 4 | 07-08-2011 04:12 AM |
![]() |
Jamal NUMAN | Word | 2 | 07-03-2011 03:11 AM |
"Microsoft Excel Application" missing in the "Component Services" on win08 | sword.fish | Excel | 0 | 02-26-2010 02:09 PM |