Exportar folha como arquivo CSV UTF-8 (usando Excel-VBA)
Gostaria de exportar um arquivo que criei no CSV UTF-8 usando o VBA. Da busca de quadros de mensagens, eu encontrei o seguinte código que converte um arquivo para UTF-8 (desta discussão):
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
No entanto, esse código só converte um arquivo não UTF-8 em UTF-8. Se eu fosse salvar meu arquivo em não-UTF-8 e depois convertê-lo em UTF-8, ele já teria perdido todos os caracteres especiais que ele continha, tornando o processo inútil!
O que eu quero fazer é salvar um arquivo aberto em UTF-8 (CSV). Existe alguma maneira de fazer isso com o VBA?
n.b. Eu também fiz esta pergunta noFórum 'ozgrid'. Fechará os dois segmentos juntos se eu encontrar uma solução.