View Single Post
  #10   Report Post  
Posted to microsoft.public.excel.programming
NickHK NickHK is offline
external usenet poster
 
Posts: 4,391
Default Importing Text files w/o losing special characters

Tony,
Looking the first 16 bytes of your file in a Hex editor, you have:
24 24 31 35 38 20 20 00 00 00 00 00 00 20 20 31

The "20"=decimal 32, which is a normal space.
The "00" are = vbNullChar and are not printable, I get a "" in Word. Not
sure where your "y with 2 dots above them" came from.
As such, do they actually mean anything ?

Your data seems such a mix of formats, I doubt Excel would be able to make
much sense of it.

You would be better writing your own parsing routine :
<Air Code
Open "the file" For Input
Do until EndOfFile
LineInput ToAVariable
Call DecideWhatThisLineMeans
'Process the data
Loop
Close file

NickHK

"T_o_n_y" wrote in message
...
Thank you, Nick, for showing me how to upload the file. Here is the link

for
the file:
http://www.savefile.com/files/150039
To answer your question, the text file data is not fixed with but I've

tried
fixed width as well as delimited...nothing works for me...the characters

are
always stripped away.

"NickHK" wrote:

Tony,
Are the columns fixed width, as the parameter dataType:=xlFixedWidth
suggests ?
Are these special characters, ASCII value 255 ?

As for uploading a samle of the data,
http://savefile.com/

NickHK

"T_o_n_y" wrote in message
...
I need to import text files into Excel without losing special

characters.
I've tried several methods, but each time Excel imports in the file,

ignoring
those characters. The following is an example line, but what you

can't
see
are the 6 special characters which appear between the $$158 and the 1

8!

$$158 1 8 4.50 1.0000 0.8000 3.0010 1.5740

I know they are there, however since I opened the document using Word,
which displays them as a y with 2 dots above them.

My Excel VBA code needs to import these characters so that it doesn't

get
lost when extracting the data using MID(,,,) function. The text file

were
generated using old FORTRAN programs, and there are thousands of

them...my
VBA routines need to access these files in order to modernize our

system.

Examples of what I've tried (all of these ignore the y characters)

Workbooks.OpenText Filename:=fname, Origin:=437, _
StartRow:=1, dataType:=xlFixedWidth, FieldInfo:=Array(0, 2)

With ActiveSheet.QueryTables.Add(Connection:="TEXT;" & fname,
Destination:=Cells(2, Col))

Open FName For Input Access Read As #1
While Not EOF(1)
Line Input #1, WholeLine
Cells(RowNdx, ColNdx).Value = WholeLine
RowNdx = RowNdx + 1
Wend
Close #1

I would upload an example file showing the characters if someone tells

me
how. I would also tell you what the characters are, again, if someone

tells
me how.

Thanks,
Tony