0

The following code works fine in an Excel VBA module

Sub test()

    Dim restReq, url, apiKey
    url = "https://some.server.com/?param1=123"
    apiKey = "123342545"
    Set restReq = CreateObject("Microsoft.XMLHTTP")
    
    restReq.Open "GET", url, False
    restReq.SetRequestHeader "accept", "application/json"
    restReq.SetRequestHeader "X-ApiKey", apiKey
    restReq.send ("")
    
    'MsgBox restReq.getAllResponseHeaders
    MsgBox restReq.responseText

End Sub

But when I run the exactly same code from Visual Studio Code, I get this non helpful error message:

MSXML3.DLL A security problem occurred.

Any ideas, where the difference could be?

BigBen
  • 46,229
  • 7
  • 24
  • 40
Prefect73
  • 321
  • 3
  • 14
  • Try using `CreateObject("MSXML2.XMLHTTP.6.0")` instead. – Étienne Laneville Jun 16 '23 at 20:08
  • This results in: MSXML6.DLL A security problem occurred. – Prefect73 Jun 17 '23 at 16:37
  • Sounds like a context and cert store issue. Meaning: Excel might be capable of accessing the Windows certificate store in your user context, but VS Code may not. See if switching to use `MSXML2.ServerXMLHTTP` and ignoring all cert errors by adding `restReq.setOption 2, 13056` helps any. – leeharvey1 Jun 17 '23 at 17:42
  • With this change it says: Certificate needed for client authorization. Shouldn't exactly this be avoided by option2? – Prefect73 Jun 17 '23 at 17:50

0 Answers0