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 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
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?
Edit: I have now asked this question on Stack Overflow as well, due to lack of response here.