Sub SaveJSONToFile(ByVal jsonString As String, ByVal filePath As String)
    ' Create a new file and write the JSON string to it
    Dim fileObject As Object
    Set fileObject = CreateObject("Scripting.FileSystemObject").CreateTextFile(filePath)
    fileObject.WriteLine jsonString
    fileObject.Close
End Sub

Sub ConvertExcelToJSONAndSaveToFile()
    ' Convert Excel data to JSON string
    Dim excelRange As Range
    Set excelRange = Range("AB6:AC13")
    Dim jsonString As String
    jsonString = ExcelToJSON(excelRange)
    
    ' Load existing JSON data from file
    Dim OutputFileNum As Integer
    OutputFileNum = FreeFile()
    Open "C:\Users\joanpla\Desktop\output.json" For Append As #OutputFileNum
    Print #OutputFileNum, jsonString
    Close #OutputFileNum
   
    ' Convert second Excel range to JSON
    Dim excelRange2 As Range
    Set excelRange2 = Range("K18:P19")
    Dim jsonString2 As String
    jsonString2 = ExcelToJSON(excelRange2)
    
    ' Combine existing and new JSON data
    Dim finalJsonText As String
    finalJsonText = "[" & jsonString & "," & jsonString2 & "]"
    
    ' Save JSON string to file
    Dim filePath As String
    filePath = "C:\Users\joanpla\Desktop\output.json"
    SaveJSONToFile finalJsonText, filePath
End Sub
