I have the below code to replace tabs with commas in a text document:
Const ForReading = 1
Const ForWriting = 2
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFile = objFSO.OpenTextFile("Path:\CSV.txt", ForReading)
strText = objFile.ReadAll
strTab = vbTab
strText = Replace(strText, strTab, ",")
objFile.Close
Set objFile = objFSO.OpenTextFile("Path:\CSV.txt", ForWriting)
objFile.Write strText
objFile.Close
This works fine on a unicode text document that I create myself, however throws up an error when used on a unicode text document created from excel.
Line: 16 Char: 1 Error: Invalid procedure call or argument Code:800A0005
Here is an example of a text file created from excel that gives the error:
Can anyone see what is different about this text document that would be causing the error?
EDIT: I have just tried writing the result to a new text document instead of overwriting the same one, but this has just given a garbled result in the document:
ÿþa 黐멸ȯ , , , , ,
, , , , , , ,
, , , , , , ,
EDIT2: the suggestion of using TristateTrue from 'Siddharth Rout' gets me past the initial 'Invalid procedure call' error, but now i'm stuck with the garbled Chinese character output - Can anyone advise as to how to fix this?
objFile.Write strText