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 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422
| ' Si Early Binding
' Activer les références
' Microsoft HTML Objects Library
' Microsoft Internet Controls
' Test très grossier sur Hostos 29 59
' version 2002 : 76 s 224 s
' 2007 : 37 s 43 s
Private Declare Function QueryPerformanceCounter Lib "kernel32" (X As Currency) As Boolean
Private Declare Function QueryPerformanceFrequency Lib "kernel32" (X As Currency) As Boolean
Option Explicit
Sub Dispo()
With ShDatas
.Columns("A:B").Columns.AutoFit
.Columns("C:C").Columns.AutoFit
End With
With ShDatas.Buttons("BtnHostos1")
.Width = ShDatas.Cells(3, 3).Width
.Left = ShDatas.Cells(3, 3).Left
.Top = ShDatas.Cells(3, 3).Top + 2
.Height = 20
.Placement = xlFreeFloating
.PrintObject = False
End With
With ShDatas.Buttons("BtnHostos2")
.Left = ShDatas.Buttons("BtnHostos1").Left
.Top = ShDatas.Cells(8, 3).Top
.Width = ShDatas.Buttons("BtnHostos1").Width
.Height = ShDatas.Buttons("BtnHostos1").Height
.Placement = xlFreeFloating
.PrintObject = False
End With
End Sub
Private Sub Kill_IE()
Dim RetVal As Long
' Parametres Taskkill
' http://technet.microsoft.com/en-us/library/bb491009.aspx
RetVal = Shell("Taskkill /im iexplore.exe /f", 0)
End Sub
Private Sub RchHosto(sRch As String)
Dim IE As Object
Dim PageHtml As Object
Dim sStr As String, sDep As String, sTmp As String
Dim sBrute As String, Ar() As String
Dim sSep As String, i As Long, j As Long, Pos As Long, Pos2 As Long
Dim LastRow As Long, sPage As String, Q() As String
Dim Page As Long, Nb As Long, s As String
Dim Debut As Currency, Fin As Currency, Freq As Currency
Const ParG As String = "("
QueryPerformanceCounter Debut
Application.StatusBar = ""
' Effacer fichiers temp et historique Internet Explorer
Shell "RunDll32.exe InetCpl.cpl,ClearMyTracksByProcess 8"
Shell "RunDll32.exe InetCpl.cpl,ClearMyTracksByProcess 1"
' Effacer la feuille Datas
With ShDatas
.Activate
.Columns("A:B").Clear
.Columns("A:B").Interior.ColorIndex = xlNone
.Range("C12").Select
End With
DoEvents
Application.StatusBar = "Connexion en cours"
Set IE = CreateObject("InternetExplorer.Application")
IE.Visible = False
' 09 Mars 2010
' Ne fonctionnait pas sur le site pour le Nord (59) plus de 100 réponses
' Après contact WebMaster fhf@fhf.fr Correction affectuée le 09 Mars 2010
' 14 Mars 2010
' Saint Pierre et Miquelon (975) ainsi que Mayotte (976) n'apparaissent pas sur la carte
' mais donne bien des résultats pour une requête externe via Excel
' par contre quid de la Polynésie Française (987) ou de la Nouvelle Calédonie (988)
sDep = sRch
sSep = vbCrLf
sPage = 1
sStr = "http://etablissements.hopital.fr/resultat_annuaire.php?loc=" & sDep & "&item=hopital&session=clear"
' UNINITIALIZED = 0
' READYSTATE_LOADING = 1
' READYSTATE_LOADED = 2
' READYSTATE_INTERACTIVE = 3
' READYSTATE_COMPLETE = 4
IE.navigate sStr
Do Until IE.readyState = 4
DoEvents
Loop
Set PageHtml = IE.document
sBrute = PageHtml.body.innerText
Set PageHtml = Nothing
' Retrouver le nombre de pages
' pas très élégant
Pos = InStr(sBrute, "Pages de résultats :")
If Pos > 0 Then
i = Len("Pages de résultats :")
Pos2 = InStr(Mid$(sBrute, Pos, 50), "[")
Q = Split(Trim$(Mid$(sBrute, Pos + i + 1, Pos2 - i - 2)), " ")
Else
Erase Q
ReDim Preserve Q(0)
Q(0) = 1
End If
sBrute = ""
Nb = UBound(Q) + 1
Erase Q
' On redémarre de la page 1 à Nb
For Page = 1 To Nb
sPage = Page
sStr = "http://etablissements.hopital.fr/resultat_annuaire.php?loc=" & sDep & "&item=hopital&page=" & sPage
IE.navigate sStr
Do Until IE.readyState = 4
DoEvents
Loop
Set PageHtml = IE.document
sBrute = sBrute & sSep & PageHtml.body.innerText
Set PageHtml = Nothing
Application.StatusBar = "Extraction Infos Page : " & Page & " / " & Nb
Next Page
IE.Quit
Set IE = Nothing
Kill_IE
DoEvents
With Application
.ScreenUpdating = False
.StatusBar = "Formatage et Epuration des données ... "
End With
Ar = Split(sBrute, sSep)
With ShDatas
For i = 1 To UBound(Ar)
.Range("A" & i) = Trim$(Ar(i))
Next i
' Nettoyage par suppression des lignes contenant un certain texte
LastRow = .Range("A" & Rows.Count).End(xlUp).Row
' On commence à partir de la dernière ligne
For i = LastRow To 1 Step -1
If InStr(.Range("A" & i), "Pages de résultats :") > 0 Then .Range("A" & i).Delete Shift:=xlUp
If InStr(.Range("A" & i), "Définitions utiles ") > 0 Then .Range("A" & i).Delete Shift:=xlUp
If InStr(.Range("A" & i), "»") > 0 Then .Range("A" & i).Delete Shift:=xlUp
If InStr(.Range("A" & i), "La liste des résultats") > 0 Then .Range("A" & i).Delete Shift:=xlUp
If InStr(.Range("A" & i), "Il s'agit ") > 0 Then .Range("A" & i).Delete Shift:=xlUp
If InStr(.Range("A" & i), "iPhone") > 0 Then .Range("A" & i).Delete Shift:=xlUp
If InStr(.Range("A" & i), "Vos ") > 0 Then .Range("A" & i).Delete Shift:=xlUp
If InStr(.Range("A" & i), "L'hôpital ") > 0 Then .Range("A" & i).Delete Shift:=xlUp
If InStr(.Range("A" & i), "Le dico médical :") > 0 Then .Range("A" & i).Delete Shift:=xlUp
If InStr(.Range("A" & i), "en clics") > 0 Then .Range("A" & i).Delete Shift:=xlUp
If InStr(.Range("A" & i), "Nos métiers ") > 0 Then .Range("A" & i).Delete Shift:=xlUp
If InStr(.Range("A" & i), "Espace Pro") > 0 Then .Range("A" & i).Delete Shift:=xlUp
If InStr(.Range("A" & i), "Les partenaires") > 0 Then Range("A" & i).Delete Shift:=xlUp
If InStr(.Range("A" & i), "métiers") > 0 Then .Range("A" & i).Delete Shift:=xlUp
If InStr(.Range("A" & i), "Aller au contenu") > 0 Then .Range("A" & i).Delete Shift:=xlUp
If InStr(.Range("A" & i), "droitsL'hôpital") > 0 Then .Range("A" & i).Delete Shift:=xlUp
If InStr(.Range("A" & i), "et vousComment") > 0 Then .Range("A" & i).Delete Shift:=xlUp
If InStr(.Range("A" & i), "en clics") > 0 Then .Range("A" & i).Delete Shift:=xlUp
If InStr(.Range("A" & i), "Vous êtes ici") > 0 Then .Range("A" & i).Delete Shift:=xlUp
If InStr(.Range("A" & i), "Votre recherche") > 0 Then .Range("A" & i).Delete Shift:=xlUp
If InStr(.Range("A" & i), "Entrez") > 0 Then .Range("A" & i).Delete Shift:=xlUp
If InStr(.Range("A" & i), "Précisez") > 0 Then .Range("A" & i).Delete Shift:=xlUp
If InStr(.Range("A" & i), "Entrer") > 0 Then .Range("A" & i).Delete Shift:=xlUp
If InStr(.Range("A" & i), "Comment") > 0 Then .Range("A" & i).Delete Shift:=xlUp
If InStr(.Range("A" & i), "Aidez-vous") > 0 Then .Range("A" & i).Delete Shift:=xlUp
If InStr(.Range("A" & i), "Fédération Hospitalière") > 0 Then .Range("A" & i).Delete Shift:=xlUp
If InStr(.Range("A" & i), "Définitions utiles") > 0 Then .Range("A" & i).Delete Shift:=xlUp
If InStr(.Range("A" & i), "Google") > 0 Then .Range("A" & i).Delete Shift:=xlUp
If InStr(.Range("A" & i), "Dépend de :") > 0 Then .Range("A" & i).Delete Shift:=xlUp
' Tranformation de l'adresse su site internet
s = "Site internet :"
If InStr(.Range("A" & i), s) > 0 Then
sTmp = .Range("A" & i)
sTmp = Trim$(Right$(sTmp, Len(sTmp) - Len(s)))
.Hyperlinks.Add Anchor:=.Range("A" & i), Address:=sTmp, TextToDisplay:=sTmp
End If
' Tranformation de l'adresse EMail
s = "Email :"
If InStr(.Range("A" & i), s) > 0 Then
sTmp = .Range("A" & i)
sTmp = Trim$(Right$(sTmp, Len(sTmp) - Len(s)))
.Hyperlinks.Add Anchor:=.Range("A" & i), Address:="mailto:" & sTmp, TextToDisplay:=sTmp
End If
' Doublon CAMP CAMP
s = "CAMP CAMP"
If InStr(.Range("A" & i), s) > 0 Then
sTmp = .Range("A" & i)
sTmp = Trim$(Replace(sTmp, s, "CAMP"))
.Range("A" & i) = sTmp
End If
' Doublon Consulations Consultations
s = "Consulations Consultations"
If InStr(.Range("A" & i), s) > 0 Then
sTmp = .Range("A" & i)
sTmp = Trim$(Replace(sTmp, s, "Consultations"))
.Range("A" & i) = sTmp
End If
Pos = InStr(.Range("A" & i), "capacité.")
If Pos > 0 Then
sTmp = .Range("A" & i)
sTmp = Mid$(sTmp, Pos + Len("capacité."), Len(sTmp))
.Range("A" & i) = Trim$(sTmp)
End If
Pos = InStr(.Range("A" & i), "Capacité totale :")
If Pos > 0 Then
sTmp = Left$(.Range("A" & i), Pos - 1)
.Range("A" & i) = Trim$(sTmp)
End If
Application.StatusBar = "Nettoyage : " & LastRow - i + 1 & " / " & LastRow
DoEvents
Next i
' Insertion d'une ligne de séparation vierge APRES Adresse
LastRow = .Range("A" & Rows.Count).End(xlUp).Row
For i = LastRow To 1 Step -1
If InStr(.Range("A" & i), "Adresse") > 0 Then .Range("A" & i + 1).Insert Shift:=xlDown
Application.StatusBar = "Adresse 1/2 : " & LastRow - i + 1 & " / " & LastRow
Next i
DoEvents
' Suppression de ligne AVANT Adresse
LastRow = .Range("A" & Rows.Count).End(xlUp).Row
For i = 1 To LastRow
If InStr(.Range("A" & i), "Adresse") > 0 Then .Range("A" & i - 1).Delete Shift:=xlUp
Application.StatusBar = "Adresse 2/2 : " & i & " / " & LastRow
Next i
DoEvents
' Suppression des lignes vierges
LastRow = .Range("A" & Rows.Count).End(xlUp).Row
For i = LastRow To 1 Step -1
If .Range("A" & i) = "" And .Range("A" & i + 1) = "" Then .Range("A" & i).Delete Shift:=xlUp
Application.StatusBar = "Suppression Lignes Vides : " & LastRow - i + 1 & " / " & LastRow
Next i
DoEvents
' Suppression 1ere ligne qui est vierge
.Range("A1").Delete Shift:=xlUp
' Suppression infos inutiles dans 1ere ligne de chaque hosto
' Nb de Places et "En savoir plus"
LastRow = .Range("A" & Rows.Count).End(xlUp).Row
For i = 1 To LastRow
Pos = InStr(.Range("A" & i), "En savoir plus")
If Pos > 0 Then
sTmp = .Range("A" & i)
sTmp = Trim$(Left$(sTmp, Pos - 2) & Mid$(sTmp, Pos + Len("En savoir plus")))
.Range("A" & i) = sTmp
End If
Application.StatusBar = "Suppression Infos : " & i & " / " & LastRow
Next i
DoEvents
' Suppression 1. 2. 3. 4. 5. etc
LastRow = .Range("A" & Rows.Count).End(xlUp).Row
j = 1
For i = 1 To LastRow
s = j & "."
Pos = InStr(.Range("A" & i), s)
If Pos > 0 Then
sTmp = .Range("A" & i)
sTmp = Trim$(Right$(sTmp, Len(sTmp) - Len(s)))
.Range("A" & i) = sTmp
j = j + 1
End If
Application.StatusBar = "Suppression N° : " & i & " / " & LastRow
Next i
DoEvents
' Suppression "Adresse :"
LastRow = .Range("A" & Rows.Count).End(xlUp).Row
s = "Adresse : "
For i = 1 To LastRow
sTmp = .Range("A" & i)
Pos = InStr(sTmp, s)
If Pos > 0 Then .Range("A" & i) = Trim$(Right$(sTmp, Len(sTmp) - Len(s)))
Application.StatusBar = "Suppression Adresse : " & i & " / " & LastRow
Next i
DoEvents
' Suppression "Type de Strcuture"
LastRow = .Range("A" & Rows.Count).End(xlUp).Row
s = "Type de structure :"
For i = 1 To LastRow
sTmp = .Range("A" & i)
Pos = InStr(sTmp, s)
If Pos = 1 Then .Range("A" & i).Delete Shift:=xlUp
If Pos > 1 Then .Range("A" & i) = Trim$(Left$(sTmp, Pos - 1))
Application.StatusBar = "Suppression Type : " & i & " / " & LastRow
Next i
DoEvents
' Suppression "( ....)"
LastRow = .Range("A" & Rows.Count).End(xlUp).Row
For i = 1 To LastRow
sTmp = .Range("A" & i)
Pos = InStr(sTmp, ParG)
If Pos > 0 Then .Range("A" & i) = Trim$(Left$(sTmp, Pos - 1))
Application.StatusBar = "Suppression ( .... ) : " & i & " / " & LastRow
Next i
DoEvents
' Suppression "- Secteur" "- secteur"
LastRow = .Range("A" & Rows.Count).End(xlUp).Row
For i = 1 To LastRow
sTmp = .Range("A" & i)
Pos = InStr(sTmp, "- Secteur")
If Pos > 0 Then .Range("A" & i) = Trim$(Left$(sTmp, Pos - 1))
Pos = InStr(sTmp, "- secteur")
If Pos > 0 Then .Range("A" & i) = Trim$(Left$(sTmp, Pos - 1))
Application.StatusBar = "Suppression Secteur : " & i & " / " & LastRow
Next i
DoEvents
' Colorier les cellules qui se terminent par ... signe de troncage
LastRow = .Range("A" & Rows.Count).End(xlUp).Row
For i = 1 To LastRow
If Right$(.Range("A" & i), 3) = "..." Then .Range("A" & i).Interior.ColorIndex = 36
Application.StatusBar = "Coloration Ligne >= 78 : " & i & " / " & LastRow
Next i
' Décaler Téléphone
LastRow = .Range("A" & Rows.Count).End(xlUp).Row
For i = LastRow To 1 Step -1
If InStr(.Range("A" & i), "Téléphone") > 0 Then
sTmp = .Range("A" & i)
.Range("B" & i - 1) = .Range("A" & i)
.Range("A" & i) = ""
.Range("A" & i & ":B" & i).Delete Shift:=xlUp
End If
Application.StatusBar = "Décalage Téléphone : " & LastRow - i + 1 & " / " & LastRow
Next i
' Décaler adresse site internet
LastRow = .Range("A" & Rows.Count).End(xlUp).Row
For i = LastRow To 1 Step -1
If InStr(.Range("A" & i), "http") > 0 Then
sTmp = .Range("A" & i)
.Range("B" & i) = sTmp
.Hyperlinks.Add Anchor:=.Range("B" & i), Address:=sTmp, TextToDisplay:=sTmp
.Range("A" & i).Clear
.Range("A" & i) = .Range("A" & i + 1)
.Range("A" & i + 1).Clear
End If
Application.StatusBar = "Décalage Http : " & LastRow - i + 1 & " / " & LastRow
Next i
DoEvents
' Décaler EMail
LastRow = .Range("A" & Rows.Count).End(xlUp).Row
For i = LastRow To 1 Step -1
If InStr(.Range("A" & i), "@") > 0 Then
sTmp = .Range("A" & i)
.Range("B" & i) = sTmp
.Hyperlinks.Add Anchor:=.Range("B" & i), Address:="mailto:" & sTmp, TextToDisplay:=sTmp
.Range("A" & i).Clear
.Range("A" & i) = .Range("A" & i + 1)
.Range("A" & i + 1).Clear
End If
Application.StatusBar = "Décalage EMail : " & LastRow - i + 1 & " / " & LastRow
Next i
DoEvents
' Suppression des lignes vierges
LastRow = .Range("A" & Rows.Count).End(xlUp).Row
For i = LastRow To 1 Step -1
If .Range("A" & i) = "" And .Range("A" & i + 1) = "" And .Range("B" & i) = "" And .Range("B" & i + 1) = "" Then
.Range("A" & i & ":B" & i).Delete Shift:=xlUp
End If
Application.StatusBar = "Suppression Lignes Vides : " & LastRow - i + 1 & " / " & LastRow
Next i
DoEvents
End With
Dispo
ShDatas.PageSetup.PrintArea = "$A$1:$B$" & LastRow
QueryPerformanceCounter Fin
QueryPerformanceFrequency Freq
With Application
.ScreenUpdating = False
.StatusBar = "Terminé : " & Format((Fin - Debut) / Freq, "0.00 s")
End With
End Sub
Sub RchNumDep1()
RchHosto ShDatas.Range("NumDep1")
End Sub
Sub RchNumDep2()
RchHosto ShDatas.Range("NumDep2")
End Sub |
Partager