VBA - CreateText file method - encoding doesn't work

makiwara

Board Regular
Joined
Mar 8, 2018
Messages
171
Hi! I tried to make a json file using VBA, but seems that certain characters are missing.

- the json file looks okay (every character is displayer when I open it)
- but when I try to read the json file from VSC (text editor which read snippets from the json file) then certain characters are missing (In Hungarian there is á,é,í) so i think that somehow the encoding is not right

Could somebody help me out how could I add specific encoding to my code? Thank you very much, I am really stucked with this one

Have a nice day!

1599843028554.png



VBA Code:
    '' Output the JSON string to a new document
    'Documents.Add.Content.Text = strJSON
    ' Objects required to backup and open the JSON file
    Dim fs As Scripting.FileSystemObject, ts As Scripting.TextStream
    Dim strDocumentName As String, strJSONFilePath As String, strBackupOfJSONFilePath As String
74  Set fs = CreateObject("Scripting.FileSystemObject")

    ' Construct the corresponding JSON file path
75  strDocumentName = d.Name
76  strJSONFilePath = "C:\Users\" & Environ$("Username") & "\AppData\Roaming\Code\User\snippets\" & _
        Left(strDocumentName, InStrRev(strDocumentName, ".")) & "json"
    ' Construct the corresponding backup JSON file path
77  strBackupOfJSONFilePath = "C:\Users\" & Environ$("Username") & "\AppData\Roaming\Code\User\snippets\BACKUP\" & _
        "(" & Replace(Now(), ":", ".") & ")" & Left(strDocumentName, InStrRev(strDocumentName, ".")) & "json"
    ' Backup the JSON file

78  If fs.FileExists(strJSONFilePath) Then
79      fs.MoveFile strJSONFilePath, strBackupOfJSONFilePath
80  End If
    ' Create the new JSON file
   
81  fs.CreateTextFile(strJSONFilePath, True, False).Write strJSON
82  MsgBox "Done", vbInformation, "MSWordTableToJSON"
83  Exit Sub
 

Excel Facts

What do {} around a formula in the formula bar mean?
{Formula} means the formula was entered using Ctrl+Shift+Enter signifying an old-style array formula.
Utf8 would solve the problem, but I can't figure out how to do that, none of the solutions seems to be working
 
Upvote 0

Forum statistics

Threads
1,215,020
Messages
6,122,709
Members
449,093
Latest member
Mnur

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top