'Excel VBA Function Error "Application Defined or object defimed error"

enter image description here

Function GetInfoview(InfoviewID As String)

On Error GoTo ErrMsg

 Dim objRequest As Object
Dim strUrl As String
Dim blnAsync As Boolean
Dim strResponse As String
Dim JsonObj As String
Dim Jsondata As String
Dim ws As Worksheet


Dim i As Long
Dim ID As String
ID = InfoviewID


Set objRequest = CreateObject("MSXML2.XMLHTTP")



strUrl = "API URL"

blnAsync = True

With objRequest
    .Open "GET", strUrl, False
    
    .Send
    
    Dim response As String
response = objRequest.ResponseText
    
End With
  Set JsonObj = JsonConverter.ParseJson(response)
  Set Jsondata = JsonObj("InfoviewData")
  
  
  Dim activeRow As Integer
  Dim activeColumn As Integer
  
  activeRow = ActiveCell.Row
  activeColumn = ActiveCell.Column
  
  
  Set ws = Worksheets(ActiveSheet.Name)
 ws.Cells(activeRow, activeColumn) = JsonObj("Name")
 
 ws.Cells(activeRow + 1, activeColumn) = "Name"
 ws.Cells(activeRow + 1, activeColumn + 1) = "Description"
 ws.Cells(activeRow + 1, activeColumn + 2) = "Units"
 ws.Cells(activeRow + 1, activeColumn + 3) = "Value"
 i = activeRow + 2
 For Each Item In JsonObj("InfoviewData")
 ws.Cells(i, activeColumn) = Item("Name")
 ws.Cells(i, activeColumn + 1) = Item("Description")
 ws.Cells(i, activeColumn + 2) = Item("Units")
 ws.Cells(i, activeColumn + 3) = Item("currentValue")("Value")
 i = i + 1
 Next
 
'ActiveCell.Formula = "=GetInfoview(""41462"")"
 


 
Done:

Exit Function
ErrMsg:
MsgBox "There seems to be an error" & vbCrLf & Err.Description

End Function

I am getting this error in ws.Cell function. please tell me how to resolve this. Am i doing correct way or not.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source