Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 32
Default Unreadable characters in file with Print #File in VBA

I have a line in a text file in wich I want to replace some text.
I read a line of the file, check if it is the line to be modified. If
it is not than I go to the next line and so on till the end of the
file.
If it is the line to be modified than I replace the line part with the
correct text and want to write the corrected line back to the file with
Print #File.
So far looks good, but when I look in the corrected file in stead of
good characters I only see ascii squares.
(It is not the whole story but a short version of the actions)
Can someone help me with this please?

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4,391
Default Unreadable characters in file with Print #File in VBA

You cannot just change some text in the middle of a file. (Well, if the
number of characters is the same, you could use Binary mode, but that does
not appear to be the case)
So you would need to read all unchanged text, write that to new file. Change
the incorrect line, write that to the file. Continue.

As long as your file are reasonably size, <5MB, you can read the whole file
into a string variable. Work on the variable with VBAs normal text functions
(Left, Instr, etc) and then write the variable to a new file. Kill the old
file if necessary. e.g.

Dim FileText As String
Dim FileNum As Integer

Const TestFilePath As String = "C:\Test.txt"

FileNum = FreeFile
Open TestFilePath For Input As #FileNum
FileText = Input$(LOF(FileNum), FileNum)
Close #FileNum

Debug.Print FileText
'Process the text in memeory
'And then write to a new file

NickHK

"pieros" wrote in message
ups.com...
I have a line in a text file in wich I want to replace some text.
I read a line of the file, check if it is the line to be modified. If
it is not than I go to the next line and so on till the end of the
file.
If it is the line to be modified than I replace the line part with the
correct text and want to write the corrected line back to the file with
Print #File.
So far looks good, but when I look in the corrected file in stead of
good characters I only see ascii squares.
(It is not the whole story but a short version of the actions)
Can someone help me with this please?



Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
excel found unreadable content in file..... do you want to recover madds Excel Discussion (Misc queries) 4 September 1st 09 07:21 PM
make characters unreadable widman Excel Discussion (Misc queries) 6 May 19th 09 01:59 AM
error - unreadable content in pivot table file - how do I find it BarbC Excel Worksheet Functions 1 March 30th 09 06:09 PM
Wrong Ascii characters with VBA Print #File command pieros Excel Programming 2 December 4th 06 01:24 PM
excel file unreadable - bad repair scandisk. Peter Excel Discussion (Misc queries) 0 November 1st 06 09:47 AM


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

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"