根据以下代码,我只能导入一个JSON文件。如何同时导入多个JSON文件?
Private Sub CommandButton3_Click()
Dim jsonText As String
Dim FSO As New FileSystemObject
Dim JsonTS As TextStream
myfile = Application.GetOpenFilename(fileFilter:="JSON file (*.json), *.json")
If myfile <> False Then
Set JsonTS = FSO.OpenTextFile(myfile, ForReading)
jsonText = JsonTS.ReadAll
JsonTS.Close
Else
MsgBox ("File not Selected")
Exit Sub
End If
Set jsonObject = JsonConverter.ParseJson(jsonText)
答案 0 :(得分:0)
我想您希望用户能够选择多个文件(请在下次提问时更加清楚)。
如果是,请从这里继续工作:
filespec = Application.GetOpenFileName(FileFilter:="JSON file (*.json), *.json", Title:="Get File", MultiSelect:=True)
For i = 1 To UBound(filespec)
' Better put the contents of this For Loop in a separate Sub
Set JsonTS = FSO.OpenTextFile(filespec(i), ForReading)
jsonText = JsonTS.ReadAll
JsonTS.Close
Set jsonObject = JsonConverter.ParseJson(jsonText)
.....
Next i