0

I had a piece of code to send data to a HTTP end point

Set xhr = CreateObject("MSXML2.XMLHTTP")
xhr.Open "POST", URL, False
xhr.setRequestHeader "Content-Type", "application/x-www-form-urlencoded"

Data = "volumeDate=" & URLEncode(VolumeDate) & "&" & "volume=" & URLEncode(Volume)
xhr.Send Data

I want to have a try catch block to handle if it didnt connect to the URL or if it returned something apart from a 200

How do I do it?

Martijn Pieters
  • 1,048,767
  • 296
  • 4,058
  • 3,343
Prateek Narendra
  • 1,837
  • 5
  • 38
  • 67
  • Try/Catch is not available in VBA. [Here's a very similar question](https://stackoverflow.com/questions/30188584/vba-try-and-catch-ms-outlook). – MatSnow Oct 06 '17 at 06:01
  • 1
    VBA has error handling, and/or you can check the `status` of the response. VBA is not VB.Net or some other language though, so you need to do a bit of Googling on VBA. – Tim Williams Oct 06 '17 at 06:06

1 Answers1

0

Error handling in VBA is based on the On Error statement. Take a look at the Error Handling In VBA for more information.

I'd suggest creating a COM add-in instead of VBA macros. You will be able to check the error code easily and handle exceptions gracefully. See Walkthrough: Creating Your First VSTO Add-In for Outlook to get started quickly.

Community
  • 1
  • 1
Eugene Astafiev
  • 47,483
  • 3
  • 24
  • 45