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
| Option Explicit
Const ForReading = 1, ForWriting = 2, ForAppending = 8
Const xlCenter = -4108
Dim fso, Fich, Ret, IP, Host, TB, I, oXL, WBK, Sht, Ligne
Set fso = CreateObject("Scripting.FileSystemObject")
Set fich = fso.OpenTextFile("Source.txt", ForReading, False)
Set oXL = CreateObject("Excel.Application")
oXL.Visible = False
Set WBK = oXL.WorkBooks.Add()
Set Sht = WBK.Worksheets(1)
Sht.Columns(1).ColumnWidth = 18
Sht.Range("A1","B1").HorizontalAlignment = xlCenter
Sht.Cells(1,1) = "HOSTNAME"
Sht.Cells(1,2) = "IP"
Ligne = 0
Do While Not fich.AtEndOfStream
Ret = fich.ReadLine
TB = Split(Ret, ",")
For I = LBound(TB) To UBound(TB)
TB(I) = Trim(TB(I))
If InStr(1, TB(I), "hostname=", vbTextCompare) > 0 Then
Host = Mid(TB(I),10)
Ligne = Ligne + 1
Sht.Cells(1+Ligne,1) = Host
ElseIf InStr(1, TB(I), "IP=", vbTextCompare) > 0 Then
IP = Mid(TB(I),4)
Sht.Cells(1+Ligne,2) = IP
End If
Next
Loop
oXL.DisplayAlerts = False
WBK.SaveAs "C:\Temp\Dest.xlsx"
' Pour tester :
oXL.Visible = True ' A mettre en commentaire pour ne pas afficher excel
' Pour fermer excel(même s'il n'est pas visible), on enlève le commentaire des 4 lignes suivantes :
' oXL.Quit
' Set WBK = Nothing
' Set Sht = Nothing
' Set oXL = Nothing |
Partager