ASCII text file import more than 65536 entries

D

DK

Hello:
I have used this macro to import the ASCII text file in excel. It is
importing everything in the column A. I need to divide that into
multiple columns as the normal import does. Can someone suggest a quick
way of doing this?

Sub LargeFileImport()
'Dimension Variables
Dim ResultStr As String
Dim FileName As String
Dim FileNum As Integer
Dim Counter As Double
'Ask User for File's Name
FileName = Application.GetOpenFilename
'Check for no entry
If FileName = "" Then End
'Get Next Available File Handle Number
FileNum = FreeFile()
'Open Text File For Input
Open FileName For Input As #FileNum
'Turn Screen Updating Off
Application.ScreenUpdating = False
'Create A New WorkBook With One Worksheet In It
Workbooks.Add Template:=xlWorksheet
'Set The Counter to 1
Counter = 1
'Loop Until the End Of File Is Reached
Do While Seek(FileNum) <= LOF(FileNum)
'Display Importing Row Number On Status Bar
Application.StatusBar = "Importing Row " & _
Counter & " of text file " & FileName
'Store One Line Of Text From File To Variable
Line Input #FileNum, ResultStr
'Store Variable Data Into Active Cell
If Left(ResultStr, 1) = "=" Then
ActiveCell.Value = "'" & ResultStr
Else
ActiveCell.Value = ResultStr
End If
'For xl95 change 65536 to 16384
If ActiveCell.Row = 65536 Then
'If On The Last Row Then Add A New Sheet
ActiveWorkbook.Sheets.Add
Else
'If Not The Last Row Then Go One Cell Down
ActiveCell.Offset(1, 0).Select
End If
'Increment the Counter By 1
Counter = Counter + 1
'Start Again At Top Of 'Do While' Statement
Loop
'Close The Open Text File
Close
'Remove Message From Status Bar
Application.StatusBar = False
End Sub
 
D

DK

The format is
02/22/2005 09:10p <DIR> ..
02/22/2005 07:10a 85 Business.url

I need these in different columns. Please advise.
 
D

Dave Peterson

Do your import as normal, but then select that column and use
Data|Text to columns
Fixed width and
finish up.

You'll have to do this for each worksheet that gets the imported data.
 
D

DK

Hello Dave,
Thanks for your reply. I tried text to columns but it did not work for
me.
For files which have less than 65536 rows, I use this macro to import
and it works wonderfully. Is there a way that this functionality can be
incorporated in the LargeImportFiles macro?

Public Sub ImportTextFile(FName As String)

Dim RowNdx As Integer
Dim ColNdx As Integer
Dim WholeLine As String
Dim Pos As Integer
Dim NextPos As Integer
Dim SaveColNdx As Integer

Application.ScreenUpdating = False
'On Error GoTo EndMacro:

SaveColNdx = ActiveCell.Column
RowNdx = ActiveCell.Row

Open FName For Input Access Read As #1

EndMacro:
On Error GoTo 0
Application.ScreenUpdating = True
Close #1

End Sub
Public Sub DoTheImport()
Dim FName As Variant

FName = Application.GetOpenFilename _
(filefilter:="Text Files(*.txt),*.txt,All Files (*.*),*.*")
If FName = False Then
MsgBox "You didn't select a file"
Exit Sub
End If

ImportTextFile CStr(FName)
Workbooks.OpenText FileName:= _
FName, Origin:=xlWindows, StartRow:=1, DataType:=xlFixedWidth,
FieldInfo:= _
Array(Array(0, 1), Array(10, 1), Array(21, 1), Array(29, 1),
Array(39, 1))

End Sub
 
D

Dave Peterson

You could incorporate data|text to columns into your code that does the
importing, but you say it didn't work. (I've never seen it fail, though. If I
were you I'd try it again.)

Alternatively (and I think more work and slower) would be to parse the line when
you were reading it.

I'd try data|text to columns once more.

If it didn't work, share some more details.
 
D

dbahooker

use a database; Excel is for fucking retards and babies.

-Aaron
ADP Nationalist
 

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