Plain Text appends mystery data to file

1

1388-2/HB

Using word 2003, we have a massive archive of legacy text files; plain DOS
text files that I've given users a UI for opening up in Word.

If the user makes a change to one of these files, some of the documents
consistantly append the following data to the end of the text file when it
saves it back to the disk:

vbCrLf & "??" & vbCrLf (x4)
vbCrLf (x13)

For example, textfile S051234.txt will contain this, initially:

"S051234

- Data data data
- Data data data"

I'll open it in word (Plain Text format), type "something" on line 2,
ActiveDocument.Save, & .Close. Opening up the S051234.txt file in notepad
(or word, or whatever else) now shows this data to be in the file:

"S051234
something
- Data data data
- Data data data
??

??

??

??












"

I'm at a total loss as to why word is appending the "??" and the CR/LF's at
the end of the file when it saves it.

When performing a Save As... and you get that little text previewer for your
encoding choise, it shows the ??'s and the line feeds in the preview box.
None of the encoding formats availble for my choosing would change the fact
that Word was insisting upon appending this data to the end of the file.
 
S

Shell

In response to the post:
Using word 2003, we have a massive archive of legacy text files; plain DOS
text files that I've given users a UI for opening up in Word.

If the user makes a change to one of these files, some of the documents
consistantly append the following data to the end of the text file when it
saves it back to the disk:

vbCrLf & "??" & vbCrLf (x4)
vbCrLf (x13)

For example, textfile S051234.txt will contain this, initially:

"S051234

- Data data data
- Data data data"

I'll open it in word (Plain Text format), type "something" on line 2,
ActiveDocument.Save, & .Close. Opening up the S051234.txt file in notepad
(or word, or whatever else) now shows this data to be in the file:

"S051234
something
- Data data data
- Data data data
??

??

??

??












"

I'm at a total loss as to why word is appending the "??" and the CR/LF's at
the end of the file when it saves it.

When performing a Save As... and you get that little text previewer for your
encoding choise, it shows the ??'s and the line feeds in the preview box.
None of the encoding formats availble for my choosing would change the fact
that Word was insisting upon appending this data to the end of the file.

The file is probably getting closed before the save can complete if
the two steps are being performed one after another in code. The
simple method of seperating the two steps by the closure of another
(The "Case" statement and the "If" statement) can help stop this.

Try putting the Save inside a dialog to save, if its dirty. Then put
the .Close the next step after the End If. Like this:

<vaporware>

If Not myDocument.Saved then
Select Case _
MsgBox("Save File?, vbYesNoCancel, "File not saved...")
Case Is = vbCancel
'bypass .Close without saving
Exit Sub
Case Is = vbNo
'Do nothing and close
Case Else
myDocument.Save Now
End Select
End If
myDocument.Close

</vaporware>

If you put the .Close right after the .Save:
<like this>
If .Save And .Close Then...
you can be cutting off the close file process of the saved file by
closing the file before it's done closing the file...you see what I
mean? You may be seeing the Goo that exists after a file
write...before the EOF can be written.

I wonder if it would write the file correctly when you step through
the code with F8. Be sure to give the system time to finish the Save
before hitting F8 again, to start the Close.

If that doesn't work, post code and a hex dump of the files (before
and after) and we'll probably find it has something to do with the use
of Clipboard data...who knows.

Shell
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top