Originally Posted by
fransajp
Hi
I need VBA code to remove a end of file character from a Notepad file please.
I've tried using the code in Open notepad, find and replace text with the filename, but VBA sees the end of file character as the end of the document and thus the code breaks("Input past end of file").
Example:
Name Age
Len 19
Frans 27
If the document contains the above, how could I replace the with a space?
Thank you
Try this code, change file names to suit
Sub Demo()
Dim search As String
search = ""
Dim repl As String
repl = " "
Dim text As String
Dim arr As Variant
Dim line As String
Dim item As Variant
Open "C:\tmp1.txt" For Binary Access Read Lock Read As #1
text = Input$(LOF(1), #1)
Close #1
arr = Split(text, vbNewLine)
Open "C:\tmp2.txt" For Output As #2 '<--temporary file
For Each item In arr
line = Replace(CStr(item), search, repl, 1, -1)
Print #2, line
Next
Close #2
Kill "C:\tmp1.txt"
Name "C:\tmp2.txt" As "C:\tmp1.txt"
End Sub
~'J'~