Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.excel.programming
|
|||
|
|||
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
Posted to microsoft.public.excel.programming
|
|||
|
|||
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 |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
excel found unreadable content in file..... do you want to recover | Excel Discussion (Misc queries) | |||
make characters unreadable | Excel Discussion (Misc queries) | |||
error - unreadable content in pivot table file - how do I find it | Excel Worksheet Functions | |||
Wrong Ascii characters with VBA Print #File command | Excel Programming | |||
excel file unreadable - bad repair scandisk. | Excel Discussion (Misc queries) |