creal69360
XLDnaute Junior
Bonjour,
Je souhaiterais importer une seule colonne de mon fichier texte dans ma feuille Excel ( la délimitation étant effectuée avec des ";"). Voici mon code d'importation:
	
	
	
	
	
		
N'ayant pas trouvé de paramètre permettant de choisir la colonne à récupérer j'ai cherché sur internet une procédure permettant de mettre le fichier texte dans un tableau mais je n'arrive toujours pas à récupérer une seule colonne:
	
	
	
	
	
		
Merci d'avance!
	
		
			
		
		
	
				
			Je souhaiterais importer une seule colonne de mon fichier texte dans ma feuille Excel ( la délimitation étant effectuée avec des ";"). Voici mon code d'importation:
		Code:
	
	
	With ActiveSheet.QueryTables.Add(Connection:= _
        "TEXT;" & cotations_import.zt_chemin, Destination:=Range("$d$2"))
        '.CommandType = 0
        '.Name = "Ing 2014"
        .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 = False
        .TextFileTabDelimiter = True
        .TextFileSemicolonDelimiter = True
        .TextFileCommaDelimiter = False
        .TextFileSpaceDelimiter = False
        .TextFileColumnDataTypes = Array(1, 1, 1, 1, 1, 1, 1)
        .TextFileTrailingMinusNumbers = True
         .Refresh BackgroundQuery:=False
    End With
	
		Code:
	
	
	Sub ImportData()
    Filename = chemin
    Open Filename For Input As #1
    Do While (Not EOF(1))
        ' In this case the file is delimited by , and contains several lines
    ' Read the file one line at the time
    Input #1, Streng
    'Input streng into and array
    StrArray = Split(Streng, ",")
    Call WriteToExcel(StrArray)
    Loop
    Close #1
End Sub
Sub WriteToExcel(StrArray)
MsgBox CStr(StrArray(10))
     For J = LBound(StrArray) To UBound(StrArray)
       'Do what you want to do with the data
    Next J
End Sub
	Merci d'avance!
			
				Dernière édition: