Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 11
Default Convert textfiles into excel

Hi

I have text files with more than 65536 lines which I want to convert to
excel (I don't want to get into ACCESS, Foxpro,etc). It must copy, say, 60000
into sheet1; copy 60001-120000 into sheet2, and so on till the entire text
file is converted.

Regards
Mani

  #2   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 5,441
Default Convert textfiles into excel

Mani,

Below is the standard large file import macro...

HTH,
Bernie
MS Excel MVP

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
If ActiveCell.Row = 60000 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



"Maniv" wrote in message
...
Hi

I have text files with more than 65536 lines which I want to convert to
excel (I don't want to get into ACCESS, Foxpro,etc). It must copy, say, 60000
into sheet1; copy 60001-120000 into sheet2, and so on till the entire text
file is converted.

Regards
Mani



  #3   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 11
Default Convert textfiles into excel


Hi Bernie

Thanks a ton.. I have been going through the various replies / code that you
post at this portal.. Pl keep up the good work..

Warm regards
Mani


"Bernie Deitrick" wrote:

Mani,

Below is the standard large file import macro...

HTH,
Bernie
MS Excel MVP

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
If ActiveCell.Row = 60000 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



"Maniv" wrote in message
...
Hi

I have text files with more than 65536 lines which I want to convert to
excel (I don't want to get into ACCESS, Foxpro,etc). It must copy, say, 60000
into sheet1; copy 60001-120000 into sheet2, and so on till the entire text
file is converted.

Regards
Mani




  #4   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 5,441
Default Convert textfiles into excel

Kind of you to say, but, well, this code certainly isn't mine. It was
copied off the MS web site about the turn of the century ;-)

Bernie
MS Excel MVP


"Maniv" wrote in message
...

Hi Bernie

Thanks a ton.. I have been going through the various replies / code that
you
post at this portal.. Pl keep up the good work..

Warm regards
Mani



  #5   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 144
Default Convert textfiles into excel

I used the above script to import a text file with about 150k lines. All the
data was imported, but it never asked me how I wanted the columns formatted
so everything was lumped into a single cell per row. Is there a way to have
the wizard pop up and allow the user to determine where the column breaks
should be and perhaps allow the user to select which row to start the import?

The users will need to import various text files with different columns of
data so I can not easily create a macro that will automatically separate the
data into columns. The ability to use the wizard would be ideal.

We are running Excel 2003 SP2. Any help would be appreciated.


"Bernie Deitrick" wrote:

Kind of you to say, but, well, this code certainly isn't mine. It was
copied off the MS web site about the turn of the century ;-)

Bernie
MS Excel MVP


"Maniv" wrote in message
...

Hi Bernie

Thanks a ton.. I have been going through the various replies / code that
you
post at this portal.. Pl keep up the good work..

Warm regards
Mani




Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Convert Project template for Excel Amy Excel Discussion (Misc queries) 0 September 8th 06 04:00 PM
Running Excel 2000 VBA Application on Excel 2003 Excel Worksheet Functions 0 August 8th 06 06:04 PM
How do I convert Excel 2003 to Excel 98 format? Lady Layla New Users to Excel 8 March 31st 05 12:47 AM
How do I convert a csv file to an Excel file? Anne B Excel Discussion (Misc queries) 2 March 29th 05 09:17 PM
Improve Convert function in Excel Mike VV Excel Worksheet Functions 0 February 3rd 05 04:45 AM


All times are GMT +1. The time now is 05:31 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"