Eksportuj arkusz jako plik CSV UTF-8 (przy użyciu Excel-VBA)
Chciałbym wyeksportować plik utworzony w UTF-8 CSV przy użyciu VBA. Z wyszukiwania tablic wiadomości znalazłem następujący kod, który konwertuje plik na UTF-8 (z tego wątku):
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
Jednak ten kod konwertuje tylko plik inny niż UTF-8 na UTF-8. Gdybym miał zapisać mój plik w formacie innym niż UTF-8, a następnie przekonwertować go na UTF-8, straciłby już wszystkie zawarte w nim znaki specjalne, czyniąc proces bezcelowym!
Co chcę zrobić, to zapisać otwarty plik w UTF-8 (CSV). Czy można to zrobić w VBA?
n.b. Zadałem również to pytanie na stronieforum „ozgrid”. Zamkną oba wątki razem, jeśli znajdę rozwiązanie.