0

Do anyone know how to save as UTF-8 format?

Problem is that I have scandinavian letters and ANSI do not support those.

Sub savetoText1()
    Dim FileToSave As String, lineText As String
    Dim myrng As Range, i, j

    FileToSave = ThisWorkbook.Path & "\test" & Format(Now, "yyyymmdd-hhmmss") & ".xml"

    Open FileToSave For Output As #1

    Set myrng = Range("xml!$A:A")


For i = 1 To myrng.Rows.Count
    For j = 1 To myrng.Columns.Count

    If lineText = IIf(j = 1, "", lineText & " ") & myrng.Cells(i, j) Then
    Close #1
    Exit Sub
    End If

        lineText = IIf(j = 1, "", lineText & " ") & myrng.Cells(i, j)
    Next j
    Print #1, lineText
Next i
Close #1
End Sub
FunThomas
  • 23,043
  • 3
  • 18
  • 34
Safki
  • 9
  • 1
  • [https://stackoverflow.com/a/2525196/11509084] –  Jun 18 '19 at 12:19
  • 1
    Possible duplicate of [Save text file UTF-8 encoded with VBA](https://stackoverflow.com/questions/2524703/save-text-file-utf-8-encoded-with-vba) – FunThomas Jun 18 '19 at 12:21
  • 1
    Possible duplicate of [VBA : save a file with UTF-8 without BOM](https://stackoverflow.com/questions/31435662/vba-save-a-file-with-utf-8-without-bom) – Florent B. Jun 18 '19 at 13:36
  • Partly yes. Problem is that I have no skils to add UTF-8 "machine" to my already build vba skript. So would be nice if someone can help me? about modifiyng my vba skript to create UTF-8 output to .xml file. Thank you already for answers. – Safki Jun 18 '19 at 19:32
  • There is a MSXML library that you can use to write XML files. That approach is probably preferable in this case. – L8n Jun 21 '19 at 07:11

0 Answers0