ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Discussion (Misc queries) (https://www.excelbanter.com/excel-discussion-misc-queries/)
-   -   Importing text file (https://www.excelbanter.com/excel-discussion-misc-queries/13434-importing-text-file.html)

Jillianno

Importing text file
 
I am importing a rather larger text file into excel, the entire thing will
not import onto one sheet. How do I import what did not fit onto the first
sheet without reimporting what I just imported

Jim Rech

You can slice it into several text files offline. Copy the code at the end
of this message into Notepad and save it with a .VBS extension.
Double-click it to run.
--
Jim Rech
Excel MVP

"Jillianno" wrote in message
...
|I am importing a rather larger text file into excel, the entire thing will
| not import onto one sheet. How do I import what did not fit onto the
first
| sheet without reimporting what I just imported

Dim fso, fileSource, fileDest
Dim fileSourceNoExt,fileSourceExt
Dim lineCount, txtLine
Dim wsh, tempFile
Dim fileCount, dotPos

Set fso = CreateObject("Scripting.FileSystemObject")
Set wsh = CreateObject("WScript.Shell")
''Set sh = CreateObject("Shell.Application")

tempFile = InputBox("Enter the full path and name of file", "Long Text File
Parser")

''The following would not return a file, just a folder object, even tho with
the 16896 it displays files
''tempFile = sh.BrowseForFolder(0, "Select a Folder", 16896, "c:\")

If tempFile < "" Then
If fso.FileExists(tempFile) Then
dotPos = InStrRev(tempFile,".")
If dotPos 0 Then
fileSourceNoExt = Left(tempFile, dotPos-1)
fileSourceExt = Mid(tempFile,dotPos)
Else
fileSourceNoExt = tempFile
End If
Set fileSource = fso.OpenTextFile(tempFile)
Do While fileSource.AtEndOfLine < True
If lineCount = 0 Then
FileCount = FileCount + 1
Set fileDest = fso.CreateTextFile(fileSourceNoExt & FileCount &
fileSourceExt, True)
End If
txtLine = fileSource.ReadLine
fileDest.WriteLine txtLine
lineCount = lineCount + 1
If lineCount = 65536 Then
fileDest.Close
lineCount = 0
End If
Loop

fileSource.Close

wsh.Popup "Done!", 1, "Long Text File Parser"
Else
wsh.Popup "Source file not found", 2, "Long Text File Parser"
End if
End If




All times are GMT +1. The time now is 10:10 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com