title: Handling REST API Handling in Excel VBA Macro
body: <p>The VBA code below is supposed to call a REST API to grant user access to the file or not.  If the REST API returns allow then the code should close normally and grant access, if the REST API retuns disallow then the program should notify user and close workbook.  If there is no Internet access, then the user should be notified and the work book should be closed.</p>
  
  <p>My question is how do I code so the REST API response is handled by the macro properly so that it will either end normally or close due to the disallow response from url?</p>
  
  <p>Here is the VBA code so far:</p>
  
  <pre><code>Private Sub Workbook_activate()
  
  Application.EnableCancelKey = xlDisabled
  
  ' Run the Error handler "ErrHandler" when an error occurs.
  
  On Error GoTo Errhandler
  
  
  ActiveWorkbook.FollowHyperlink Address:="https://mysite.com/licensing/getstatus.php?", NewWindow:=True
  
  ' If response is allow
  
  ' Exit the macro so that the error handler is not executed.
  
  ****what goes here??****
  
        Exit Sub
  
  ' If response is disallow
  
  ****what goes here??****
  
        MsgBox "Your license key is not valid. Please check your key or contact customer service."
  
         ActiveWorkbook.Close SaveChanges:=False
  
  
  Errhandler:
  
        ' If no Internet Access, display a message and end the macro.
        MsgBox "An error has occurred. You need Internet access to open the software."
  
         ActiveWorkbook.Close SaveChanges:=False
  
  End Sub
  </code></pre>