Build an Excel file from one-line text file.


Posted by Raja Y. Anastas on October 30, 2001 2:27 AM

Hi,

I would be grateful if you can tell me how, in Excel 2000, to import a one-line text file containing multiples of 512-character records and put each 512-character record in a seperate cell vertically, e.g. the first 512 charachters to go into cell A1, the second set of 512 characters to go into cell A2, and so forth until the end of file.

TIA



Posted by Paul Akkermans on October 30, 2001 6:21 AM

Sub test()

Dim strFilename As String
strFilename = Application.GetOpenFilename

If strFilename = "False" Then Exit Sub

Application.ScreenUpdating = False


Open strFilename For Input As #1

i = 1
cnt = 1
Do While Not EOF(1)
Buffer = Input(1, #1)
Range("A" & i).Select
Selection.Value = Selection.Value & Buffer
cnt = cnt + 1
If cnt Mod 512 = 0 Then
i = i + 1
End If
Loop
Close #1
End Sub