Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Word / Programming / October 2005

Tip: Looking for answers? Try searching our database.

Plain Text appends mystery data to file

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
1388-2/HB - 04 Oct 2005 22:21 GMT
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.
Shell - 05 Oct 2005 10:25 GMT
In response to the post:
On Tue, 4 Oct 2005 14:21:03 -0700, "1388-2/HB" <3@4.com> stated...and
I replied:

>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.
[quoted text clipped - 38 lines]
>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
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.