Sub Macro1_Ter()
Dim typeCol, Chemin$
Application.ScreenUpdating = False
Chemin = "C:\Users\STAPLE\Documents\bdd.txt"
typeCol = Array(4, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1)
With ActiveSheet.QueryTables.Add(Connection:="TEXT;" & Chemin, Destination:=Cells(1))
.FieldNames = True
.PreserveFormatting = True
.RefreshStyle = xlInsertDeleteCells
.SaveData = True
.AdjustColumnWidth = True
.RefreshPeriod = 0
.TextFilePlatform = 850
.TextFileStartRow = 1
.TextFileParseType = xlDelimited
.TextFileTextQualifier = xlTextQualifierDoubleQuote
.TextFileTabDelimiter = True
.TextFileColumnDataTypes = typeCol
.TextFileDecimalSeparator = "."
.TextFileTrailingMinusNumbers = True
.Refresh BackgroundQuery:=False
.Delete
End With
End Sub
Re
Je te laisse chercher ce que j'ai ajouté et ce que cela change
VB:Sub Macro1_Ter() Dim typeCol, Chemin$ Application.ScreenUpdating = False Chemin = "C:\Users\STAPLE\Documents\bdd.txt" typeCol = Array(4, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1) With ActiveSheet.QueryTables.Add(Connection:="TEXT;" & Chemin, Destination:=Cells(1)) .FieldNames = True .PreserveFormatting = True .RefreshStyle = xlInsertDeleteCells .SaveData = True .AdjustColumnWidth = True .RefreshPeriod = 0 .TextFilePlatform = 850 .TextFileStartRow = 1 .TextFileParseType = xlDelimited .TextFileTextQualifier = xlTextQualifierDoubleQuote .TextFileTabDelimiter = True .TextFileColumnDataTypes = typeCol .TextFileDecimalSeparator = "." .TextFileTrailingMinusNumbers = True .Refresh BackgroundQuery:=False .Delete End With End Sub
Sub Importer()
Application.ScreenUpdating = False
Workbooks.OpenText ThisWorkbook.Path & "\Source.txt", Local:=True
ActiveSheet.UsedRange.Copy ThisWorkbook.Sheets(1).[A1] 'copier-coller
ActiveWorkbook.Close
Sheets(1).UsedRange.Replace ".", ".", xlPart 'remplace le point par... le point
End Sub
Sub Importer()
Application.ScreenUpdating = False
Workbooks.OpenText ThisWorkbook.Path & "\bdd.txt", Local:=True, DecimalSeparator:="."
ActiveSheet.UsedRange.Copy ThisWorkbook.Sheets(1).[A1] 'copier-coller
ActiveWorkbook.Close
End Sub
QueryTable aussijob75 à dit:permet de préciser le séparateur décimal du fichier texte
.TextFileDecimalSeparator = "."
D'ailleurs, on pourrait faire l'import manuellement pour aller dans ce sens.Re,
Oui je sais mais je ne serais sans doute pas le seul à avoir ce fichier, c'est que je voudrais qu'il soit le plus simple possible
Sub Importer()
Dim texte$, s$, n&, a$(), b$()
Open ThisWorkbook.Path & "\bdd.txt" For Input As #1 'accès au fichier
Do While Not EOF(1) 'EndOfFile: fin du fichier
Line Input #1, texte 'récupère la ligne
s = Split(texte, vbTab)(0) 'item de la 1ère colonne
texte = Format(s, "m/d/yyyy") & Mid(texte, Len(s) + 1) 'date au format US en 1ère colonne
ReDim Preserve a(n) 'tableau VBA, base 0
a(n) = texte 'stocke le texte dans le tableau a
n = n + 1
Loop
Close #1
ReDim b(UBound(a), 0) 'base 0
For n = 0 To UBound(a)
b(n, 0) = a(n) 'transposition
Next
Application.ScreenUpdating = False
With [A1].Resize(n)
.Value = b 'restitution
.TextToColumns .Cells(1), xlDelimited, Tab:=True, DecimalSeparator:="." 'commande Convertir
End With
Columns.AutoFit
End Sub
Bonsoir thunder23, JM,
Pas trop compris ni essayé de comprendre ce qu'à fait JM mais bon voyez ceci :
Fichiers zippés joints à télécharger dans le même dossier (le bureau).VB:Sub Importer() Application.ScreenUpdating = False Workbooks.OpenText ThisWorkbook.Path & "\Source.txt", Local:=True ActiveSheet.UsedRange.Copy ThisWorkbook.Sheets(1).[A1] 'copier-coller ActiveWorkbook.Close Sheets(1).UsedRange.Replace ".", ".", xlPart 'remplace le point par... le point End Sub
A+
Application.GetOpenFilename("Text Files (*.txt), *.txt", , "Sélectionnez un fichier")
Pas clair du tout, mettre quoi à la 1ère ligne vide ?si par exemple A1 n'est pas vide de mettre à la première ligne vide
Sub Importer()
Dim fichier As Variant, texte$, s$, n&, a$(), b$()
ChDir ThisWorkbook.Path 'dossier initial
fichier = Application.GetOpenFilename("Fichiers textes,*.txt")
If fichier = False Then Exit Sub
Open fichier For Input As #1 'accès au fichier
Do While Not EOF(1) 'EndOfFile: fin du fichier
Line Input #1, texte 'récupère la ligne
s = Split(texte, vbTab)(0) 'item de la 1ère colonne
texte = Format(s, "m/d/yyyy") & Mid(texte, Len(s) + 1) 'date au format US en 1ère colonne
ReDim Preserve a(n) 'tableau VBA, base 0
a(n) = texte 'stocke le texte dans le tableau a
n = n + 1
Loop
Close #1
ReDim b(UBound(a), 0) 'base 0
For n = 0 To UBound(a)
b(n, 0) = a(n) 'transposition
Next
Application.ScreenUpdating = False
With [A1].Resize(n)
.Value = b 'restitution
.TextToColumns .Cells(1), xlDelimited, Tab:=True, DecimalSeparator:="." 'commande Convertir
End With
Columns.AutoFit
End Sub
Bonjour le fil, thunder23, job75
Bonjour à toi aussi thunder23
•>thunder23
Pas de réaction au message#18...
Sinon, au final, tu abandonnes QueryTable ?
Bonjour thunder23, JM,
Pas clair du tout, mettre quoi à la 1ère ligne vide ?
Pour choisir le fichier avec la méthode de mon post #23 :
Dossier (3 bis).VB:Sub Importer() Dim fichier As Variant, texte$, s$, n&, a$(), b$() ChDir ThisWorkbook.Path 'dossier initial fichier = Application.GetOpenFilename("Fichiers textes,*.txt") If fichier = False Then Exit Sub Open fichier For Input As #1 'accès au fichier Do While Not EOF(1) 'EndOfFile: fin du fichier Line Input #1, texte 'récupère la ligne s = Split(texte, vbTab)(0) 'item de la 1ère colonne texte = Format(s, "m/d/yyyy") & Mid(texte, Len(s) + 1) 'date au format US en 1ère colonne ReDim Preserve a(n) 'tableau VBA, base 0 a(n) = texte 'stocke le texte dans le tableau a n = n + 1 Loop Close #1 ReDim b(UBound(a), 0) 'base 0 For n = 0 To UBound(a) b(n, 0) = a(n) 'transposition Next Application.ScreenUpdating = False With [A1].Resize(n) .Value = b 'restitution .TextToColumns .Cells(1), xlDelimited, Tab:=True, DecimalSeparator:="." 'commande Convertir End With Columns.AutoFit End Sub
A+
Re
•>thunder23
[aparté]
Il ne s'agit pas mal ou de bien.
L'usage c'est de signaler par un lien quand on poste sa question sur plusieurs forums.
Cela évite de répondre à une question potentiellement déjà résolue ailleurs.
Ni plus, ni moins.
PS: Pour ta gouverne
[/aparté]Multipostage — Wikipédia
fr.wikipedia.org
Pour le reste, je ne parle pas de polémique.
Je pose juste une question qui se résume à:
Quelle solution (code) tu as retenu pour la problématique?