jbesclapez
Active Member
- Joined
- Feb 6, 2010
- Messages
- 275
Hello Family!
I am using a script to save a Range into a XML file in my Documents folder.
I just realised now that when I save it with german characters like ö then Excel does not save it corrrectly.
I do not know why it does that. I presume Encoding, but I do not fully understand it.
I would like it to be saved exactly the way it displays in Excel.
Here is the guilty script below. How would you change it to make it work?
I am using a script to save a Range into a XML file in my Documents folder.
I just realised now that when I save it with german characters like ö then Excel does not save it corrrectly.
I do not know why it does that. I presume Encoding, but I do not fully understand it.
I would like it to be saved exactly the way it displays in Excel.
Here is the guilty script below. How would you change it to make it work?
VBA Code:
Sub btn_ExportADDXML()
Dim myFile As String, rng As Range, cellValue As Variant, i As Integer, j As Integer
Dim LastRow As Long
Dim LastCol As Long
Dim ws As Worksheet
Dim dt As String
Set ws = ActiveSheet
' LastCol = WS.Cells(2, Columns.Count).End(xlToLeft).Column
' LastRow = WS.Cells(Rows.Count, LastCol).End(xlUp).row
LastRowBA = ws.Cells(Rows.Count, "BA").End(xlUp).row
myFile = Application.DefaultFilePath & "\ADD_" & ActiveSheet.name & " " & Range("B2") & Format(CStr(Now), " yyy_mm_dd_hh_mm") & ".xml"
' Set rng = WS.Range(Cells(3, LastCol), Cells(LastRow, LastCol))
Set rng = ws.Range("BA3:BA" & LastRowBA)
Open myFile For Output As #1
For i = 1 To rng.Rows.Count
For j = 1 To rng.Columns.Count
cellValue = rng.Cells(i, j).Value
If j = rng.Columns.Count Then
Print #1, cellValue
Else
Print #1, cellValue,
End If
Next j
Next i
Close #1
MsgBox ("File exported successfully. Check in your Documents folder")
End Sub