Function open_log_file() ' ' open_log_file Macro ' ' open_log_file = False Dim wbSource, wbFichierUsager As Workbook Dim strFileName As String Dim intChoice As Integer Set wbFichierUsager = ThisWorkbook ' On va appeler une application de MS Office afin de chercher et d’ouvrir le bon fichier ' Avec la commande qui suit, on indique que nous ne voulons qu’un seul fichier Application.FileDialog(msoFileDialogOpen).AllowMultiSelect = False ' On affiche l’écran de dialogue de MS Office intChoice = Application.FileDialog(msoFileDialogOpen).Show ' On s’assure que l’utilisateur a fait un choix et on récupère le nom complet du fichier If intChoice <> 0 Then strFileName = Application.FileDialog(msoFileDialogOpen).SelectedItems(1) Workbooks.Open strFileName Set wbSource = ActiveWorkbook ' Sinon, on arrête tout en notifiant l’usager Else Exit Function End If Workbooks.OpenText Filename:=strFileName, Origin:= _ xlMSDOS, StartRow:=1, DataType:=xlDelimited, TextQualifier:=xlDoubleQuote _ , ConsecutiveDelimiter:=True, Tab:=False, Semicolon:=False, Comma:= _ False, Space:=True, Other:=False, FieldInfo:=Array(Array(1, 1), Array(2, 1), _ Array(3, 1), Array(4, 1), Array(5, 1), Array(6, 1), Array(7, 1), Array(8, 1), Array(9, 1), _ Array(10, 1)), TrailingMinusNumbers:=True open_log_file = True End Function Sub Logs_analyzer() ' ' Logs_Step1 Macro ' ' ' si le répertoire contenant les logs est fixe, le renseigner ci-dessous ' ChDrive "J:" ' ChDir "J:/logs" If Not open_log_file() Then Exit Sub End If ' Dim LRow As Long Dim tDeb, tFin As Single tDeb = Timer() Columns("C:C").Select Selection.EntireColumn.Hidden = True Rows("1:1").Select Selection.Insert Shift:=xlDown, CopyOrigin:=xlFormatFromLeftOrAbove Range("A1").Select ActiveCell.FormulaR1C1 = "IP" Range("B1").Select ActiveCell.FormulaR1C1 = "IP" Range("D1").Select ActiveCell.FormulaR1C1 = "Time" Range("E1").Select ActiveCell.FormulaR1C1 = "Décalage" Range("F1").Select ActiveCell.FormulaR1C1 = "Requête" Range("G1").Select ActiveCell.FormulaR1C1 = "Status" Range("H1").Select ActiveCell.FormulaR1C1 = "Longueur" Range("I1").Select ActiveCell.FormulaR1C1 = "Referrer" Range("J1").Select ActiveCell.FormulaR1C1 = "User-Agent" Range("K1").Select ActiveCell.FormulaR1C1 = "=CONCATENATE(RC[-10],""-"",RC[-1])" Range("L1").Select ActiveCell.FormulaR1C1 = "Total" Range("K1").Select ' calculer la cellule la plus grande utilisée dans la rangée A:L LRow& = Range("A:C").Find("*", SearchOrder:=xlByRows, SearchDirection:=xlPrevious).Row Selection.AutoFill Destination:=Range("K1:K" & LRow) Range("K1:K" & LRow).Select ' Générer un lien hypertext whois sur les adresses IP dans la colonne B Range("B1").Select ActiveCell.FormulaR1C1 = _ "=HYPERLINK(CONCATENATE(""http://ip-lookup.net/index.php?ip="",RC[-1]),RC[-1])" Selection.AutoFill Destination:=Range("B1:B" & LRow) ' et masquer la colonne A désormais inutile Columns("A:A").Select Selection.EntireColumn.Hidden = True Cells.Select ActiveWorkbook.ActiveSheet.Sort.SortFields.Clear ActiveWorkbook.ActiveSheet.Sort.SortFields.Add Key:=Range( _ "K2:K" & LRow), SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:= _ xlSortNormal ActiveWorkbook.ActiveSheet.Sort.SortFields.Add Key:=Range( _ "D2:D" & LRow), SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:= _ xlSortNormal With ActiveWorkbook.ActiveSheet.Sort .SetRange Range("A1:L" & LRow) .Header = xlYes .MatchCase = False .Orientation = xlTopToBottom .SortMethod = xlPinYin .Apply End With ' ' première phase de la mise en forme ' Range("A1:L1").Select Selection.Font.Bold = True With Selection .HorizontalAlignment = xlCenter .VerticalAlignment = xlBottom .WrapText = False .Orientation = 0 .AddIndent = False .IndentLevel = 0 .ShrinkToFit = False .ReadingOrder = xlContext .MergeCells = False End With Range("A1").Select Columns("B:B").EntireColumn.AutoFit Columns("D:D").EntireColumn.AutoFit Columns("E:E").EntireColumn.AutoFit Columns("F:F").ColumnWidth = 33.43 Columns("G:G").EntireColumn.AutoFit Columns("H:H").EntireColumn.AutoFit Columns("I:I").ColumnWidth = 24.57 Columns("J:J").ColumnWidth = 24 Columns("K:K").ColumnWidth = 20.43 Columns("L:L").ColumnWidth = 28 ' préparer la colonne Total (side effect si la colonne est non initialisée) Range("L2").Select ActiveCell.FormulaR1C1 = "0" Selection.AutoFill Destination:=Range("L2:L" & LRow) Range("L2:L" & LRow).Select ' trier les informations de la feuille sur IP-User-agent en majeur et Time en mineur Columns("A:L").Select ActiveWorkbook.ActiveSheet.Sort.SortFields.Clear ActiveWorkbook.ActiveSheet.Sort.SortFields.Add Key:= _ Range("K2:K" & LRow), SortOn:=xlSortOnValues, Order:=xlAscending, DataOption _ :=xlSortNormal ActiveWorkbook.ActiveSheet.Sort.SortFields.Add Key:= _ Range("D2:D" & LRow), SortOn:=xlSortOnValues, Order:=xlAscending, DataOption _ :=xlSortNormal With ActiveWorkbook.ActiveSheet.Sort .SetRange Range("A1:L" & LRow) .Header = xlYes .MatchCase = False .Orientation = xlTopToBottom .SortMethod = xlPinYin .Apply End With Cells.Select Selection.Subtotal GroupBy:=10, Function:=xlCount, TotalList:=Array(12), _ Replace:=True, PageBreaks:=False, SummaryBelowData:=True ' Mettre en évidence (couleur) les sous-totaux ActiveSheet.Outline.ShowLevels RowLevels:=2 Selection.SpecialCells(xlCellTypeVisible).Select With Selection.Interior .Pattern = xlSolid .PatternColorIndex = xlAutomatic .Color = 65535 'jaune '.Color = 49407 'orange '.Color = 255 'rouge .TintAndShade = 0 .PatternTintAndShade = 0 End With ActiveSheet.Outline.ShowLevels RowLevels:=3 ' Les sous-totaux sont affichés. Supprimer les 0 et remplacer pas "" (neutralisation du side-effect précédent) Columns("L:L").Select Selection.NumberFormat = "0;-0;;@" ' La colonne K (notre clé unique) ne sert plus à rien : la masquer Columns("K:K").Select Selection.EntireColumn.Hidden = True Columns("L:L").ColumnWidth = 6.86 ' Mettre en place les filtres Range("B1:L1").Select Selection.AutoFilter ' Figer la ligne de titre With ActiveWindow .SplitColumn = 0 .SplitRow = 1 End With ActiveWindow.FreezePanes = True ' Les deux lignes suivantes peuvent être commentées elles ne sont là que pour avoir une idée de la performance globale tFin = Timer() MsgBox "Durée totale de l'exécution : " & Round(tFin - tDeb, 2) & " secondes. Nombre de lignes : " & LRow End Sub