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
| Dim FSO: Set FSO = CreateObject("Scripting.FileSystemObject")
'Ouverture d'Excel
Dim waExcel: Set waExcel = CreateObject("Excel.Application")
'Chemin d'accès du fichier
StrPath = "C:\"
'Ajoute \ à la fin s'il y en a pas
If Right(StrPath, 1) <> "\" Then StrPath = StrPath & "\"
'Nom du fichier
StrFich = "ControleDisque.txt"
'Existance du fichier
If FSO.FileExists(StrPath & StrFich) Then
'Rendre invisible Excel
waExcel.Visible = False
'Importe le fichier texte vers une feuille Excel avec délimiteur : Tabulation et Space
waExcel.Workbooks.OpenText StrPath & StrFich, , , , , , True, , , True
'Sélection de toutes les lignes de la feuille 1
waExcel.Worksheets(1).Cells.Select
'Tri par ordre croissant à partir de B1
waExcel.Selection.Sort Key1:=WaExcel.Worksheets(1).Range("B1"), Order1:=xlAscending, Header:= _
xlGuess, OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom, _
DataOption1:=xlSortNormal
'Sauvegarde la feuiller importer vers le chemin d'accès de départ en motifiant l'extension et en mode partagé pour éviter des erreurs
waExcel.Application.DisplayAlerts = false
waExcel.Workbooks(StrFich).SaveAs StrPath & Left(StrFich, Len(StrFich) - 4) & ".xls", , , , , , 2, True
End If
'Fermeture d'Excel
waExcel.Application.Quit |
Partager