1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84
| Sub COMPA ()
Dim r%
r = Selection.Row
Dim ie As New InternetExplorer
ie.Visible = False 'nonvisible sur l'ouverture du site'
ie.navigate ("https://www.google.fr/?gws_rd=ssl#q=" & "societe.com " & Cells(r, "C") & " " & Cells(r, "R")) 'ouvrir directement google avec la recherche des tiers'
While ie.ReadyState <> 4 'en attente qu'il soit terminé'
DoEvents
Wend
Set dmt = ie.Document
Set tbs = dmt.all.tags("a") 'chercher tous les tags a (hyperlien)'
For i = 0 To tbs.Length - 1
If InStr(tbs(i), ".html") Then 'pour tous les tiers chez societe.com, la forme formule toujours 9 chiffre nb ....+.html
a = InStr(tbs(i), ".html") 'note la position du .html'
If IsNumeric(Mid(tbs(i), a - 9, 9)) Then 'vérifier les 9 caractères avant .html sont chiffres ou pas'
s1 = Mid(tbs(i), a - 9, 9)
Exit For 'normalement la première recherche google est le bon résultat, on fini cette macro pourvu qu'on trouve le ....'
End If
End If
Next
ie.navigate ("https://www.google.fr/?gws_rd=ssl#q=" & "societe.com " & Cells(r, "C") & " " & Cells(r, "Q")) 'ouvrir directement google avec la recherche des tiers'
While ie.ReadyState <> 4 'en attente qu'il soit terminé'
DoEvents
Wend
Set dmt = ie.Document
Set tbs = dmt.all.tags("a") 'chercher tous les tags a (hyperlien)'
For i = 0 To tbs.Length - 1
If InStr(tbs(i), ".html") Then 'pour tous les tiers chez societe.com, la forme formule toujours 9 chiffre nb ...+.html
a = InStr(tbs(i), ".html") 'note la position du .html'
If IsNumeric(Mid(tbs(i), a - 9, 9)) Then 'vérifier les 9 caractères avant .html sont chiffres ou pas'
s2 = Mid(tbs(i), a - 9, 9) 'si oui, afficher ces 9 chiffres'
Exit For 'normalement la première recherche google est le bon résultat, on fini cette macro pourvu qu'on trouve le ....'
End If
End If
Next
If s1 = s2 And s1 <> vbNullString Then
Cells(r, "T") = s1
GoTo a
Else
ie.navigate ("http://www.societe.com/cgi-bin/search?champs=" & Cells(r, "C"))
Do Until ie.ReadyState = READYSTATE_COMPLETE
DoEvents
Loop
Set dmt = ie.Document
Set tbs = dmt.all.tags("div")
For i = 0 To tbs.Length - 1
If InStr(tbs(i).innerhtml, Cells(r, "R")) > 0 And InStr(tbs(i).innerhtml, ".html") > 0 Then
arr = Split(tbs(i).innerhtml, "<A class")
For j = 0 To UBound(arr)
If InStr(arr(j), Cells(r, "R")) > 0 And InStr(arr(j), ".html") > 0 Then
a = InStr(arr(j), ".html")
If IsNumeric(Mid(arr(j), a - 9, 9)) Then
Cells(r, "T") = Mid(arr(j), a - 9, 9)
GoTo a
End If
End If
Next j
End If
Next i
End If
a: ie.Quit
Set tbs = Nothing
Set dmt = Nothing
Set ie = Nothing
End Sub
Sub recursif()
Application.ScreenUpdating = False
r = Selection.Row
l = Range("A1").CurrentRegion.Rows.Count
For Each c In Range("T" & r & ":T" & l).SpecialCells(xlCellTypeVisible)
c.Select
SIRENCOMPA
Next
Application.ScreenUpdating = True
End Sub |
Partager