View Single Post
  #3   Report Post  
Posted to microsoft.public.excel.misc
MikeA MikeA is offline
external usenet poster
 
Posts: 13
Default Excel Web Query does not return hyperlink



"Joel" wrote:

It all depends on the tools and how the webpage was created. You can always
write a macro like the one below to get the links

Sub Getchemicals2()

Found = False
For Each sht In Sheets
If sht.Name = "Chemicals" Then
Found = True
Exit For
End If
Next sht
If Found = False Then
Set ChemicalSht = Sheets.Add(after:=Sheets(Sheets.Count))
ChemicalSht.Name = "Chemicals"
Else
Set ChemicalSht = Sheets("Chemicals")
ChemicalSht.Cells.ClearContents
End If


Set ie = CreateObject("InternetExplorer.Application")
ie.Visible = True

URLFolder = _
"http://www.ilo.org/public/english/protection/safework/cis/products/icsc/dtasht/"
ChemicalRowCount = 1
For Letters = 0 To 25
AlphaLetter = Chr(Asc("a") + Letters)

URL = URLFolder & AlphaLetter & "_index.htm"

'get web page
ie.Navigate2 URL
Do While ie.readyState < 4
DoEvents
Loop

Do While ie.busy = True
DoEvents
Loop

H2Found = False
For Each itm In ie.Document.all
If H2Found = False Then
If itm.tagname = "H2" Then
H2Found = True
End If
Else

If itm.tagname = "A" Then
If itm.innertext = "" Then Exit For

'chemical name
ChemicalSht.Range("A" & ChemicalRowCount) = itm.innertext
'webpage
ChemicalSht.Range("B" & ChemicalRowCount) = itm.href

ChemicalRowCount = ChemicalRowCount + 1
End If
End If
Next itm

Next Letters


End Sub


Thanks for the comprehensive example. It really helps to get a complete
working example vice a few of the key lines. Anyway, I did get something
working, but is seems like a difficult solution to maintain/reapply. A few
questions:

Is there an easy way to find the tags used on the web page; I examined the
source, but due to poor formatting (no logical text wrap) it is easy to get
lost/confused. Is there a way to search for (for example) the second table.

Do you know what is missing from the page I am using that prevents the web
query from getting the links?

thanks again, Mike