Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

import text file in excel 97

Status
Not open for further replies.

L01

Technical User
Oct 22, 2001
7
CA
I want to import a .rpt file into excel. Excel 2000 has the option of "import text file" from the "Import external data" in the "Data" menu.
However, excel 97 does NOT have this item to choose from in the menu. What can I do to import?

For VBA, I also checked the QueryTables.Add method. But the connection does not allow text for excel 97. Is this a problem with excel 97 or am I in the totally wrong direction?

Thanks for help!!
 
Hi L01,
I don't know what you want to do with the text but you may be able to modify this code to suit your needs.

Code:
Sub import_Text()

Dim fnum, x, TextFileName, TextLine
fnum = FreeFile
TextFileName = "C:\temp\test.txt" 'insert your path and filename here 

    Open TextFileName For Input As fnum
        Do While Not EOF(fnum)
        x = x + 1
            Line Input #1, TextLine
                ActiveSheet.Cells(x, 1).Value = TextLine ' or whatever you want to do with it! 
        Loop
    Close
End Sub

Mike [pipe]
 
Mike, thanks for the code.
One more thing that I'd like to know to make things easy for end users:
does Excel 97 have any built-in functions that could import the text file for us instead of us writing codes? Excel 2000 has the "Import text data" from the "Data" menu. I wonder if Excel 97 has that somewhere!?
 
Hi L01,
Just do "File", "Open" change the file type to "All Files" and select the text file you want to import, it will then run the Text Import Wizard so the info is sorted into columns as per your instructions.

Mike [pipe]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top