ChetShannon
Board Regular
- Joined
- Jul 27, 2007
- Messages
- 133
- Office Version
- 365
- Platform
- Windows
Hi,
I am getting an “Error: 91: Object variable or With block variable not set” inside a function I am running. Not sure why. My mouseover of the variables being passed to the function shows the values are present. (macro_name, strid, strURL, strfile all present.)
What might be causing this type of error?? Stumped I am!.. .Thanks.. My code for the function below.
Function GetGNPReport(macro_name As String, strid As String, strURL As String, Optional strfile As String) As String
Dim myVars As String
On Error GoTo getout
myHttp.Open "GET", strURL, False
'code failing on this GET statement above and goes to getout: as of tue 130pm error code 91
'strURL= web link removed
' myHttp.SetRequestHeader "User-Agent", macro_name & " " & strid
myHttp.Send
myHttp.waitForResponse
If myHttp.Status <> "200" Then
GetGNPReport = "Error: HTTP RESPONSE " & myHttp.Status & " - " & myHttp.StatusText
Exit Function
End If
If strfile <> "" Then
Dim mystream As TextStream
Dim myfsobj As New FileSystemObject
Set mystream = myfsobj.OpenTextFile(strfile, ForWriting, True)
mystream.Write myHttp.ResponseText
End If
GetGNPReport = myHttp.ResponseText
getout:
If Err.Number <> 0 Then
GetGNPReport = "Error: " & Err.Number & ": " & Err.Description
End If
End Function
I am getting an “Error: 91: Object variable or With block variable not set” inside a function I am running. Not sure why. My mouseover of the variables being passed to the function shows the values are present. (macro_name, strid, strURL, strfile all present.)
What might be causing this type of error?? Stumped I am!.. .Thanks.. My code for the function below.
Function GetGNPReport(macro_name As String, strid As String, strURL As String, Optional strfile As String) As String
Dim myVars As String
On Error GoTo getout
myHttp.Open "GET", strURL, False
'code failing on this GET statement above and goes to getout: as of tue 130pm error code 91
'strURL= web link removed
' myHttp.SetRequestHeader "User-Agent", macro_name & " " & strid
myHttp.Send
myHttp.waitForResponse
If myHttp.Status <> "200" Then
GetGNPReport = "Error: HTTP RESPONSE " & myHttp.Status & " - " & myHttp.StatusText
Exit Function
End If
If strfile <> "" Then
Dim mystream As TextStream
Dim myfsobj As New FileSystemObject
Set mystream = myfsobj.OpenTextFile(strfile, ForWriting, True)
mystream.Write myHttp.ResponseText
End If
GetGNPReport = myHttp.ResponseText
getout:
If Err.Number <> 0 Then
GetGNPReport = "Error: " & Err.Number & ": " & Err.Description
End If
End Function
Last edited by a moderator: