Code importer fichier texte vers excel

Fermé
tjrod Messages postés 24 Date d'inscription jeudi 20 décembre 2012 Statut Membre Dernière intervention 5 novembre 2016 - 2 oct. 2014 à 11:52
jordane45 Messages postés 38144 Date d'inscription mercredi 22 octobre 2003 Statut Modérateur Dernière intervention 21 avril 2024 - 2 oct. 2014 à 12:13
Bonjour,
ce macro importe les données texte vers excel
cela est peut être utile
vous pouvez l'améliorer si vous voulez
merci

'importe les données textes
Sub OuvreTxt()
' importer et découper le fichier texte

ChDrive "C:"
ChDir "C:"
Fichier = Application.GetOpenFilename("Texte fichiers (*.log), *.log")

'active la feuille à importer les données
Sheets("Feuil2").Activate
Cells.Select
Selection.Clear
With ActiveSheet.QueryTables.Add(Connection:= _
"TEXT;" & Fichier, Destination:=Range("$A$1"))
.Name = Split(Fichier, "/")(UBound(Split(Fichier, "/")))
.FieldNames = True
.RowNumbers = False
.FillAdjacentFormulas = False
.PreserveFormatting = True
.RefreshOnFileOpen = False
.RefreshStyle = xlInsertDeleteCells
.SavePassword = False
.SaveData = True
.AdjustColumnWidth = True
.RefreshPeriod = 0
.TextFilePromptOnRefresh = False
.TextFilePlatform = 850
.TextFileStartRow = 1
.TextFileParseType = xlDelimited
.TextFileTextQualifier = xlTextQualifierDoubleQuote
.TextFileConsecutiveDelimiter = True
.TextFileTabDelimiter = True
.TextFileSemicolonDelimiter = False
.TextFileCommaDelimiter = False
.TextFileSpaceDelimiter = False
.TextFileOtherDelimiter = "."
.TextFileOtherDelimiter = "["
.TextFileColumnDataTypes = Array(1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1)
.TextFileTrailingMinusNumbers = True
.Refresh BackgroundQuery:=False
Selection.Replace What:="Login ID:", Replacement:="", LookAt:=xlPart, SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, ReplaceFormat:=False
Selection.Replace What:=" ", Replacement:="", LookAt:=xlPart, SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, ReplaceFormat:=False
Selection.Replace What:="]", Replacement:="", LookAt:=xlPart, SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, ReplaceFormat:=False
Selection.Replace What:="User ID:", Replacement:="", LookAt:=xlPart, SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, ReplaceFormat:=False
Selection.Replace What:="User Name:", Replacement:="", LookAt:=xlPart, SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, ReplaceFormat:=False
Selection.Replace What:="Category Code:", Replacement:="", LookAt:=xlPart, SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, ReplaceFormat:=False
Selection.Replace What:="Network ID:", Replacement:="", LookAt:=xlPart, SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, ReplaceFormat:=False
Selection.Replace What:="User Type:", Replacement:="", LookAt:=xlPart, SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, ReplaceFormat:=False
End With
End Sub

1 réponse

jordane45 Messages postés 38144 Date d'inscription mercredi 22 octobre 2003 Statut Modérateur Dernière intervention 21 avril 2024 344
Modifié par jordane45 le 8/10/2014 à 01:57
C'est gentil de ta part de nous fournir ce code..
toute fois.. il existe dans ce forum une section dédiée à la dépose de codes sources et/ou de SNIPPETS..

Je t'invite à y mettre ton code.. après avoir vérifié au préalable qu'un tel code n'existe pas déjà...
Et surtout.. avant... vas lire ce qui est écrit ici :
http://codes-sources.commentcamarche.net/contents/11-charte-de-commentcamarche-net-conseils-d-ecriture#regles-pour-poster-une-nouvelle-source-ou-autre-contribution

Merci.
0
Rejoignez-nous