problem replaceall with vba code.

  • Thread starter Thread starter Maya
  • Start date Start date
M

Maya

Hi.

I wrote a procedure tha scan tx file, look for specific word and replace it
by other.
the problem I have is when the replaceable word is shorter than the
original - I got at the end of the file garbage character. That meen if I
had replaced all the apperance of the word 'red' with the word 'yellow'
which were 9 times at the txt file. I would have at the end of the txt file
21 character. If I replace with a longer word the txt file will be O.K.

I don't want to copy it to a new file.

can anyone help me with that bug.?

Thanks.
 
Hi.

I wrote a procedure tha scan tx file, look for specific word and replace it
by other.
the problem I have is when the replaceable word is shorter than the
original - I got at the end of the file garbage character. That meen if I
had replaced all the apperance of the word 'red' with the word 'yellow'
which were 9 times at the txt file. I would have at the end of the txt file
21 character. If I replace with a longer word the txt file will be O.K.

I don't want to copy it to a new file.

can anyone help me with that bug.?

Thanks.
how to you read and write that file?

my guess is that you are using get and put?
or you read fixed length?
 
Hi Maya,

If editing a text file may change its length, the only way to do it is
to read the existing file and create a new one containing the changes.
 
I manage with the problem, I copy the new txt file to tmp file, and then
'kill' the old txt file and i rename the tmp txt file to the original
name.not elegant but works....

Thanks, Maya
 
That's how all text editing programs work under the covers!

I manage with the problem, I copy the new txt file to tmp file, and then
'kill' the old txt file and i rename the tmp txt file to the original
name.not elegant but works....

Thanks, Maya
 
Back
Top