I would like to export a file I have created in UTF-8 CSV using VBA. From searching message boards, I have found the following code that converts a file to UTF-8 (from this thread):
Sub SaveAsUTF8() Dim fsT, tFileToOpen, tFileToSave As String tFileToOpen = InputBox("Enter the name and location of the file to convert"& vbCrLf & "With full path and filename ie. C:\MyFolder\ConvertMe.Txt") tFileToSave = InputBox("Enter the name and location of the file to save"& vbCrLf & "With full path and filename ie. C:\MyFolder\SavedAsUTF8.Txt") tFileToOpenPath = tFileToOpen tFileToSavePath = tFileToSave Set fsT = CreateObject("ADODB.Stream"): 'Create Stream objectfsT.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 streamfsT.LoadFromFile tFileToOpenPath: 'And write the file to the object streamfsT.SaveToFile tFileToSavePath, 2: 'Save the data to the named pathEnd Sub
However, this code only converts a non-UTF-8 file to UTF-8. If I were to save my file in non-UTF-8 and then convert it to UTF-8, it would have already lost all the special characters it contained, thus rendering the process pointless!
What I'm looking to do is save an open file in UTF-8 (CSV). Is there any way of doing this with VBA?
n.b. I have also asked this question on the 'ozgrid' forum. Will close both threads together if I find a solution.