View Single Post
  #3   Report Post  
Posted to microsoft.public.excel.misc
Dave O
 
Posts: n/a
Default Importing a .txt file issues

I've done a lot of this type of work in the past, and have used Visual
Basic to great success. I'm guessing since you even know of the
existence of the DOS command prompt FTP program you can write code, or
at least figure it out- you can also do this with the VBA compiler that
is native to Excel.

It sounds like the report contains information you want and header /
footer / whitespace information that you do not want. You are manually
deleting that stuff already, so the trick is to figure out what makes
the useful information different from the useless information and
translate that difference into a decision the computer can make. For
instance- the useful information contains a + sign delimiter. Does the
header contain that? If it does not, you could write a quick program
to open the source file, read each line, and write only the lines that
contain a + to a separate file. Then import the "plusses only" file to
Excel. Or, the header line may contain the word "Date: ", so you could
write the program to exclude lines that contain that text string.

Assume for the moment that the headers do NOT contain a + sign. To
pursue this solution, you could run code that looks like this to
"condition" the data into a useable format. This code is written for
Excel VBA, in case you do not have a Visual Basic compiler on your
computer. The apostrophe within the code indicates a comment.

Sub Kill_Headers()
'declare variables
Dim File_Line As String

Open "c:\FTP_File.txt" For Input As #1 'Open the source file
Open "c:\No_Headers.txt" For Output As #2 'Create a file for data only

Do While Not EOF(1) 'Process the source file through to the end
Line Input #1, File_Line 'read a line from the source file into
memory
If InStr(1, File_Line, "+") < 0 Then Print #2, File_Line 'write the
line to the output file if it contains a +
Loop

Close #1
Close #2
End Sub

The output file would then be free of headers, and ready for import to
Excel. You could also expand this code to write the information
directly into Excel instead of an output file, but this may be an
easier first step.

Let me know what you think- I'll be glad to help revise this sample
code to match your situation.