mwdbActuary
New Member
- Joined
- May 1, 2024
- Messages
- 1
- Office Version
- 365
- Platform
- Windows
- MacOS
I am trying to find the means of importing a locally stored self-signed Digital Certificate in to a module. This is needed for a login process to an external website after providing my username and password pair. I have the process working in VB.NET but want to transition to VBA. This is where I am currently with the code:
The Locals window would suggest that the Certificate isnt being called and the login is therefore failing. Any help or advice would be greatly appreciated after 4 days of banging my head ;(
VBA Code:
Sub Login()
Dim postData As String
Dim cert As Object
Dim request As Object
Dim dataStream As Object
Dim writer As Object
Dim stream As Object
Dim reader As Object
Dim loginResponse As Object
On Error Resume Next
postData = "username=MY_USERNAME&password=MY_PASSWORD"
Set cert = CreateObject("X509Certificate2")
cert.Import "C:\client-2048.p12", ""
Set request = CreateObject("MSXML2.ServerXMLHTTP.6.0")
request.Open "POST", "WEBSITE", False
request.setRequestHeader "X-Application", "MY_APP_KEY"
request.setRequestHeader "Content-Type", "application/x-www-form-urlencoded"
request.setRequestHeader "Accept", "application/json"
request.setClientCertificate cert
request.send postData
If request.Status = 200 Then.............................
The Locals window would suggest that the Certificate isnt being called and the login is therefore failing. Any help or advice would be greatly appreciated after 4 days of banging my head ;(