Blue1971
New Member
- Joined
- May 19, 2020
- Messages
- 15
- Office Version
- 2016
- Platform
- Windows
I have an Excel VBA function that takes a URL and returns a response.
The function works as expected.
However, if there is a problem with the URL (like the server being down), then the VBA editor pops up an error dialog.
Run-time error '-2147467259 (80004005)': Uspecified error
Instead of popping up a dialog, I would like the function to return the error message as a string.
Is there a way to return the server error as a string (without doing the HTTP call more than once)?
VBA Code:
response = GetHTTP(.ListColumns(colNameURL).DataBodyRange(n).Value)
...
Public Function GetHTTP(ByVal url As String) As String
With CreateObject("MSXML2.XMLHTTP")
.Open "GET", url, False: .Send
GetHTTP = StrConv(.responseBody, vbUnicode)
End With
End Function
The function works as expected.
However, if there is a problem with the URL (like the server being down), then the VBA editor pops up an error dialog.
Run-time error '-2147467259 (80004005)': Uspecified error
Instead of popping up a dialog, I would like the function to return the error message as a string.
Is there a way to return the server error as a string (without doing the HTTP call more than once)?