G
George J
I am trying to force a text file to be saved with Ansi encoding.
I have many text files that i am trying to import into a worksheet - one
file per cell (they are quite small), but as these text files have been
produced via an OLE, they are unicode files. When i put the text into the
cells, it still has extra characters that i don't want so i think the only
way i can do this is to resave the text files with ansi encoding.
I had tried StrConv(temp, vbfromUnicode) but there are still extra
characters there.
I had tried using
Dim xsystem, contents, temp, newtemp
Set xsystem = CreateObject("Scripting.FileSystemObject")
Set temp = xsystem.OpenTextFile(fn)
contents = temp.readall()
temp.Close
Set newtemp = xsystem.CreateTextFile(strFilePath & "\" & "gj-" &
strFilename, TristateUseDefault)
newtemp.WriteLine (contents)
newtemp.Close
But this still saves as unicode. Is there any way to force it to save as
ANSI?
I had found this code on the net, but it gives me chinese or something.
Dim InputFile As String, OutputFile As String, TextChar As String
InputFile = fn ' replace with actual path to input file
OutputFile = strFilePath & "\" & "gjj-" & strFilename ' replace with output
path
Open InputFile For Input As #1 ' Open file.
Open OutputFile For Output As #2 ' Open the output file: will either create
it or overwrite existing file
Do While Not EOF(1) ' Loop until end of file.
TextChar = Input(1, #1) ' Get one character.
' Perform any desired conversion here
Print #2, TextChar; ' Wirte to output file
Loop
Close #1 ' Close files
Close #2
Result: ഠ倊牥桴à¨à´ 匊ç¥ãˆ 〰ഷ䜊潲瑷⡨⤥›à¨ã¤±ã€®à´¶à´Š
I know you can save as Ansi in notepad, but due to the number of files, i
would really like to be able to do this in excel. I can get the text file
contents into the cells, it's just getting the text to be "normal" text.
I found some information in a VB forum:
My.Computer.FileSystem.WriteAllText("c:\x.txt", ControlChars.NewLine &
"ã‚ã sã sd", True, System.Text.Encoding.Default)
Third parameter "True" specifies appending and fourth parameter specifies
ANSI depending upon ur systems ANSI code page.
But have no idea if this is of any use for VBA.
Any tips or advice most welcome.
George
I have many text files that i am trying to import into a worksheet - one
file per cell (they are quite small), but as these text files have been
produced via an OLE, they are unicode files. When i put the text into the
cells, it still has extra characters that i don't want so i think the only
way i can do this is to resave the text files with ansi encoding.
I had tried StrConv(temp, vbfromUnicode) but there are still extra
characters there.
I had tried using
Dim xsystem, contents, temp, newtemp
Set xsystem = CreateObject("Scripting.FileSystemObject")
Set temp = xsystem.OpenTextFile(fn)
contents = temp.readall()
temp.Close
Set newtemp = xsystem.CreateTextFile(strFilePath & "\" & "gj-" &
strFilename, TristateUseDefault)
newtemp.WriteLine (contents)
newtemp.Close
But this still saves as unicode. Is there any way to force it to save as
ANSI?
I had found this code on the net, but it gives me chinese or something.
Dim InputFile As String, OutputFile As String, TextChar As String
InputFile = fn ' replace with actual path to input file
OutputFile = strFilePath & "\" & "gjj-" & strFilename ' replace with output
path
Open InputFile For Input As #1 ' Open file.
Open OutputFile For Output As #2 ' Open the output file: will either create
it or overwrite existing file
Do While Not EOF(1) ' Loop until end of file.
TextChar = Input(1, #1) ' Get one character.
' Perform any desired conversion here
Print #2, TextChar; ' Wirte to output file
Loop
Close #1 ' Close files
Close #2
Result: ഠ倊牥桴à¨à´ 匊ç¥ãˆ 〰ഷ䜊潲瑷⡨⤥›à¨ã¤±ã€®à´¶à´Š
I know you can save as Ansi in notepad, but due to the number of files, i
would really like to be able to do this in excel. I can get the text file
contents into the cells, it's just getting the text to be "normal" text.
I found some information in a VB forum:
My.Computer.FileSystem.WriteAllText("c:\x.txt", ControlChars.NewLine &
"ã‚ã sã sd", True, System.Text.Encoding.Default)
Third parameter "True" specifies appending and fourth parameter specifies
ANSI depending upon ur systems ANSI code page.
But have no idea if this is of any use for VBA.
Any tips or advice most welcome.
George