
Active Member

February 13, 2013

Hello!
I'm newby to ms excel vba.
I want to read text files where are in a folder and the data of each file to transfer in a workbook/sheet as list.
The text files there are to C:\tst.
The data of every text file has the following view:
UserName
XXXXXXXXXXXXXX
PC Name
YYYYYYYYYYYYYY
SerialNumber
ZZZZZZZZZZZZZZZ
and i want to view them to excel as:
Column 1 Column 2 Column 3
UserName PC Name SerialNumber
XXXXXXXXXXX YYYYYYYYYYY ZZZZZZZZZZZZZ
XXXXXXXXXXX YYYYYYYYYYY ZZZZZZZZZZZZZ
XXXXXXXXXXX YYYYYYYYYYY ZZZZZZZZZZZZZ
XXXXXXXXXXX YYYYYYYYYYY ZZZZZZZZZZZZZ
etc.
The only that I've done is the following, but, i receive to excel sheet, only the data of one text file at a time:
Sub ImportFromText()
Dim c As Integer, data As String
Cells.ClearContents
Open "C:\tst\FileName.txt" For Input As #1
c = 0
Do Until EOF(1)
Line Input #1, data
Worksheets("Sheet1").Range("A1").Offset(0, c) = data
c = c + 1
Loop
Close #1
End Sub
and the result:
ώUserName XXXXXXXXXXXXXX PC Name YYYYYYYYYYYYYY SerialNumber ZZZZZZZZZZZZZZZ
Could anybody help me please?
Thanks
Sotiris

VIP

Trusted Members

June 25, 2016


Active Member

February 13, 2013

Hi Sunny!
Thank you very much for your help.
This is exactly the format that I want.
The next step that I want is the "macro" to read all the files from the folder and not only one as does now. I think that must add a variable that read every file of the folder and write the data as you have make the code. Imagine that the folder has 300 files. That was my aknowlegde problem with the programming.
Is something that you can help me?
Thank you for another time.

VIP

Trusted Members

June 25, 2016


Active Member

February 13, 2013


VIP

Trusted Members

June 25, 2016


Active Member

February 13, 2013

1 Guest(s)
