Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Excel / New Users / September 2006

Tip: Looking for answers? Try searching our database.

ASCII text file import more than 65536 entries

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
DK - 07 Sep 2006 15:29 GMT
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
DK - 07 Sep 2006 15:33 GMT
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.

> Hello:
>  I have used this macro to import the ASCII text file in excel. It is
[quoted text clipped - 52 lines]
> Application.StatusBar = False
> End Sub
Dave Peterson - 07 Sep 2006 16:22 GMT
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.

> The format is
> 02/22/2005   09:10p    <DIR>    ..
[quoted text clipped - 58 lines]
> > Application.StatusBar = False
> > End Sub

Signature

Dave Peterson

DK - 07 Sep 2006 17:30 GMT
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

> Do your import as normal, but then select that column and use
> Data|Text to columns
[quoted text clipped - 65 lines]
> > > Application.StatusBar = False
> > > End Sub
Dave Peterson - 07 Sep 2006 17:40 GMT
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.

> Hello Dave,
> Thanks for your reply. I tried text to columns but it did not work for
[quoted text clipped - 118 lines]
> >
> > Dave Peterson

Signature

Dave Peterson

dbahooker@hotmail.com - 09 Sep 2006 23:17 GMT
use a database; Excel is for f.cking retards and babies.

-Aaron
ADP Nationalist

> 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
[quoted text clipped - 129 lines]
> > >
> > > Dave Peterson
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.