importing textfiles with cariagge returns into 1 cell

Z

zZyXx

Column A has names of textfiles that need to be imported into collum
B.

So far I've got this code:

colIndex = 1
For rwIndex = 1 To 10
With ActiveSheet.Cells(rwIndex, colIndex)
Location = "TEXT;S:\test\" + Mid(.Value, 3) + ".txt"
End With
With ActiveSheet.QueryTables.Add(Connection:=Location
Destination:=ActiveSheet.Cells(rwIndex, 2))
.FieldNames = True
.RowNumbers = False
.FillAdjacentFormulas = False
.PreserveFormatting = True
.RefreshOnFileOpen = False
.RefreshStyle = xlInsertDeleteCells
.SavePassword = False
.SaveData = True
.AdjustColumnWidth = True
.RefreshPeriod = 0
.TextFilePromptOnRefresh = False
.TextFilePlatform = 1252
.TextFileStartRow = 1
.TextFileParseType = xlDelimited
.TextFileTextQualifier = xlTextQualifierDoubleQuote
.TextFileConsecutiveDelimiter = False
.TextFileTabDelimiter = True
.TextFileSemicolonDelimiter = False
.TextFileCommaDelimiter = False
.TextFileSpaceDelimiter = False
.TextFileColumnDataTypes = Array(1)
.TextFileTrailingMinusNumbers = True
.Refresh BackgroundQuery:=False
End With
Next rwIndex

Is this the appropriate way to do this?
Textfiles with more than 1 line get imported into several cell
underneath eachother. I need each textfile to get imported into on
cell with all the lines in that cell. How do I do that
 
Z

zZyXx

this seems to do the trick:

Dim InputString As String, FileNum As Integer
colIndex = 1
For rwIndex = 1 To 10
With ActiveSheet.Cells(rwIndex, colIndex)
FileName = "S:\sekretnew\server\brief\04IN\SE\109\boodschap\"
Mid(.Value, 3) + ".txt"
End With
FileNum = FreeFile ' next free filenumber
Open FileName For Input As #FileNum
Line Input #FileNum, FileContent ' read a line from the textfile
While Not EOF(FileNum)
Line Input #FileNum, InputString ' read a line from th
textfile
FileContent = FileContent + Chr(10) + InputString
Wend
Close #FileNum
ActiveSheet.Cells(rwIndex, 2).Value = FileContent
Next rwInde
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top