KenCriss
Active Member
- Joined
- Jun 6, 2005
- Messages
- 326
Hi folks - I use the code below to save a regular text file as a UTF-8 file. The code works great...except the application that needs the file does not allow the BOM (byte order mark) to be at the beginning of the file. So, in the end I need a UTF-8 text file that does not have the BOM on the beginning of the file.
Options
1) Add code to rewrite the first line of the file taking out the BOM (3 bytes?) and then save the file again.
2) Change below code to save the file as UTF-8 without BOM (I am told you can do this in Notepad ++ with the File/SaveAs command but I don't know how to do that in VBA).
3) Other?
Thanks for any help
Options
1) Add code to rewrite the first line of the file taking out the BOM (3 bytes?) and then save the file again.
2) Change below code to save the file as UTF-8 without BOM (I am told you can do this in Notepad ++ with the File/SaveAs command but I don't know how to do that in VBA).
3) Other?
Code:
Sub SaveAsUTF8(sFileToSave As String)
Dim fsT, tFileToOpen, tFileToSave As String
tFileToOpen = sFileToSave
tFileToSave = sFileToSave
tFileToOpenPath = tFileToOpen
tFileToSavePath = tFileToSave
Set fsT = CreateObject("ADODB.Stream"): 'Create Stream object
fsT.Type = 2: 'Specify stream type – we want To save text/string data.
fsT.Charset = "utf-8": 'Specify charset For the source text data.
fsT.Open: 'Open the stream
fsT.LoadFromFile tFileToOpenPath: 'And write the file to the object stream
fsT.SaveToFile tFileToSavePath, 2: 'Save the data to the named path
End Sub