The following vba code works when line 4 replaced with
... Source = Json.Document(Web.Contents(""https://pidynaapst02.com/e/78df7c69-3512-4946-8d3c-f1c0e451fe80/api/v1/problem/feed?relativeTime=month""))," & Chr(13) & ...
However, in order to do it automatically, I want to replace url by a variable, as shown below:
... Source = Json.Document(Web.Contents(""" & VA & """))," & Chr(13) & ...
This is the complete vb code:
`
Sub Macro2()
VA = Sheets(1).Range("A1").Value
ActiveWorkbook.Queries.Add Name:= _
"Table 0", Formula:= _
"let" & Chr(13) & "" & Chr(10) & " Source = Json.Document(Web.Contents(""" & VA & """)," & Chr(13) & "" & Chr(10) & " result = Source[result]," & Chr(13) & "" & Chr(10) & " problems = result[problems]," & Chr(13) & "" & Chr(10) & " #""Converted to Table"" = Table.FromList(problems, Splitter.SplitByNothing(), null, null, ExtraValues." & _
"Error)," & Chr(13) & "" & Chr(10) & " #""Expanded Column1"" = Table.ExpandRecordColumn(#""Converted to Table"", ""Column1"", {""id"", ""startTime"", ""endTime"", ""displayName"", ""impactLevel"", ""status"", ""severityLevel"", ""commentCount"", ""tagsOfAffectedEntities"", ""rankedImpacts"", ""affectedCounts"", ""recoveredCounts"", ""hasRootCause""}, {""Column1.id"", ""Column1.startTime"", " & _
"""Column1.endTime"", ""Column1.displayName"", ""Column1.impactLevel"", ""Column1.status"", ""Column1.severityLevel"", ""Column1.commentCount"", ""Column1.tagsOfAffectedEntities"", ""Column1.rankedImpacts"", ""Column1.affectedCounts"", ""Column1.recoveredCounts"", ""Column1.hasRootCause""})," & Chr(13) & "" & Chr(10) & " #""Expanded Column1.tagsOfAffectedEntities"" = Table.ExpandListColumn(#" & _
"""Expanded Column1"", ""Column1.tagsOfAffectedEntities"")," & Chr(13) & "" & Chr(10) & " #""Expanded Column1.tagsOfAffectedEntities1"" = Table.ExpandRecordColumn(#""Expanded Column1.tagsOfAffectedEntities"", ""Column1.tagsOfAffectedEntities"", {""context"", ""key"", ""value""}, {""Column1.tagsOfAffectedEntities.context"", ""Column1.tagsOfAffectedEntities.key"", ""Column1.tagsOfAffectedEntit" & _
"ies.value""})" & Chr(13) & "" & Chr(10) & "in" & Chr(13) & "" & Chr(10) & " #""Expanded Column1.tagsOfAffectedEntities1"""Sheets.Add After:=ActiveSheet
With ActiveSheet.ListObjects.Add(SourceType:=0, Source:=Array( _
"OLEDB;Provider=Microsoft.Mashup.OleDb.1;Data Source=$Workbook$;Location=""Table 0""" _
, "ended Properties="""""), Destination:=Range("$A$1")).QueryTable
.CommandType = xlCmdSql
.CommandText = Array( _
"SELECT * FROM [Table 0]")
.RowNumbers = False
.FillAdjacentFormulas = False
.PreserveFormatting = True
.RefreshOnFileOpen = False
.BackgroundQuery = True
.RefreshStyle = xlInsertDeleteCells
.SavePassword = False
.SaveData = True
.AdjustColumnWidth = True
.RefreshPeriod = 0
.PreserveColumnInfo = False
.ListObject.DisplayName = "Table_0"
.Refresh BackgroundQuery:=False
End WithSelection.ListObject.QueryTable.Refresh BackgroundQuery:=False
End Sub`
It is giving error "Intialization of the data source failed. Check the database server or contact you database administrator. Make sure the external database is available, and then try the operation again. If you see this message again, create a new data source to connect to the database."
Hopefully somebody could help.