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
| Sub RécupérationDonnées()
'Variables utilisées
Dim MonHTML As String, Fichier As String, x As String, Eléments As Object
'Demande si annotations
If MsgBox("Voulez-vous ajouter des annotations ?", vbYesNo, "Demande de confirmation") = vbYes Then
Sheets("Bilan").Range("B44") = InputBox("Annotations :")
Else: Sheets("Bilan").Range("B44") = ""
End If
'Création de la boite de dialogue pour entrer la date voulue
x_Date = InputBox("Indiquer la date voulue (AAAAMMJJ)")
x_Heure = InputBox("Indiquer l'heure du document voulu (hhmmss)")
'Recherche du fichier
x = FreeFile
Fichier = "\\Chemin\" & x_Date & "_" & x_Heure & "_CampagneStatistiques.html"
'Vérification que le fichier existe
If Fichier <> "" Then
Open Fichier For Input As #x
Else
MsgBox "Fichier introuvable"
End If
'Création de l'inputation de la longueur du fichier HTML (chaîne de caractères contenu à l'intérieur)
MonHTML = Input(LOF(x), #x)
Close #x
'Document HTML virtuel en late binding
With CreateObject("htmlfile")
.write MonHTML
'Recherche un texte dans la page
Set Eléments = .getElementsByTagName("table")(1)
'Place le code outerhtml de cette table dans le clipboard du document html virtuel et colle dans la feuille de données
If .parentWindow.clipboardData.setData("Text", Eléments.outerHTML) Then
Application.ScreenUpdating = False
'Mets les données dans la feuille données voulue
With Sheets(3)
.Activate
.Cells.Clear
Cells(2, 1).Select
.Paste
End With
.parentWindow.clipboardData.clearData "Text"
End If
'Recherche texte
Set Eléments = .getElementsByTagName("span")(2)
If Eléments Is Nothing Then GoTo 5 Else
If .parentWindow.clipboardData.setData("Text", Eléments.outerHTML) Then
Application.ScreenUpdating = False
With Sheets(3)
.Activate
Cells(10, 1).Select
.Paste
End With
.parentWindow.clipboardData.clearData "Text"
End If
'Recherche un tableau dans la page
Set Eléments = .getElementsByTagName("table")(2)
'Place le code outerhtml de cette table dans le clipboard du document html virtuel et colle dans la feuille de données
If .parentWindow.clipboardData.setData("Text", Eléments.outerHTML) Then
Application.ScreenUpdating = False
'Mets les données dans la feuille données voulue
With Sheets(3)
.Activate
Cells(11, 1).Select
.Paste
End With
.parentWindow.clipboardData.clearData "Text"
End If
'Recherche un tableau dans la page
Set Eléments = .getElementsByTagName("table")(3)
'Place le code outerhtml de cette table dans le clipboard du document html virtuel et colle dans la feuille de données
If .parentWindow.clipboardData.setData("Text", Eléments.outerHTML) Then
Application.ScreenUpdating = False
'Mets les données dans la feuille données voulue
With Sheets(3)
.Activate
Cells(11, 15).Select
.Paste
End With
.parentWindow.clipboardData.clearData "Text"
End If
'Recherche texte
Set Eléments = .getElementsByTagName("span")(6)
If .parentWindow.clipboardData.setData("Text", Eléments.outerHTML) Then
Application.ScreenUpdating = False
With Sheets(3)
.Activate
Cells(16, 1).Select
.Paste
End With
.parentWindow.clipboardData.clearData "Text"
End If
'Recherche tableau
Set Eléments = .getElementsByTagName("table")(4)
If .parentWindow.clipboardData.setData("Text", Eléments.outerHTML) Then
Application.ScreenUpdating = False
With Sheets(3)
.Activate
Cells(17, 1).Select
.Paste
End With
.parentWindow.clipboardData.clearData "Text"
End If
5
'Supprimer les balises HTML
Worksheets("Données").Cells.Replace What:="<*>", Replacement:="", lookat:=xlPart, SearchOrder _
:=xlByColumns, MatchCase:=True, SearchFormat:=False, ReplaceFormat:= _
False
'Supprime les espaces
Sheets("Données").Visible = True
Sheets("Données").Select
Columns("C:C").Select
Range("C1").Activate
Selection.Replace What:=" ", Replacement:="", lookat:=xlPart, _
SearchOrder:=xlByColumns, MatchCase:=True, SearchFormat:=False, _
ReplaceFormat:=False
Sheets("Bilan").Select
Sheets("Données").Visible = False
Range("A1").Select
End Sub |
Partager