Bonjour à toutes et à tous.
Le but de cette macro est de convertir un fichier en format txt en un fichier de format xlsx.
Dans mon fichier txt il y'a trois informations séparés par des tabulations.
Première information : la date
Deuxième information : l'heure
Troisième information : Les données.
Quand mon fichier se crée en xslx, il y'a une colonne pour la date, une autre colonne l'heure et une autre pour les données.
Exactement ce que je voulais avoir. Par contre, il y'a une inversion entre le mois et le jour dans mon fichier xlsx.
Exemple : Dans mon fichier txt, la date : 01/06/2015 et dans mon fichier xlsx cela va donner 06/01/2015.
Comment faire pour corriger cela ?
Voici le code de la macro :
Sub IMPORT()
Dim nomfichier As String
nomfichier = RechercheFichier()
If nomfichier = "" Then
MsgBox "Vous n'avez sélectionné aucun fichier"
Else
Workbooks.OpenText nomfichier _
, Origin:=xlMSDOS, StartRow:=1, DataType:=xlFixedWidth, FieldInfo:= _
Array(Array(0, 1), Array(10, 1), Array(16, 1)), TrailingMinusNumbers:=True
End If
Dim extension As String
Dim style As Integer
extension = ".xlsx"
Application.ScreenUpdating = False
MsgBox ThisWorkbook.Path
With ActiveWorkbook
.SaveAs FileFormat:=xlOpenXMLWorkbook
.Close
End With
End Sub
' permet de choisir un fichier txt à un emplacement donné
Function RechercheFichier() As String
Dim fd As FileDialog
Dim nomfichier As String
Set fd = Application.FileDialog(msoFileDialogFilePicker)
With fd
.Filters.Add "fichier txt", "*.txt"
.Title = "Recherche de fichier"
'mettre le chemin du repertoire
.InitialFileName = "C:\Users\schang\downloads"
End With
If fd.Show = -1 Then nomfichier = fd.SelectedItems(1)
RechercheFichier = nomfichier
Set fd = Nothing
End Function
Merci