This article is basically an extension to my previous article How to Connect to HP QC using Excel VBA. As we know, from the previous article that QC Connection is made in two parts:
1. Authentication using QC ID and Password
2. Login with Domain and Project Name
It is a good practice to check the Connection Object – qcConnection whether Authentication and Login with Domain and Project were successful before using it.
VBA Statement to check if Authentication was Successful ?
If (QCConnection.LoggedIn True) Then MsgBox "QC User Authentication Failed" End If
VBA Statement to check if Login with Domain and Project was Successful ?
If (QCConnection.AuthenticationToken = "") Then MsgBox "QC Project Failed to Login with your Domain and Project" QCConnection.Disconnect End If
Refer the below VBA code to connect to QC with both the checks done
Function ConnectToQC() On Error Resume Next Dim QCConnection 'Create QC Connection Object to connect to QC Set QCConnection = CreateObject("TDApiOle80.TDConnection") Dim sUserName, sPassword, sDomain, sProject sUserName = "" sPassword = "" sDomain = "" sProject = "" QCConnection.InitConnectionEx "<you URL>" 'Authenticate your user ID and Password QCConnection.Login sUserName, sPassword 'Quit if QC Authentication fails If (QCConnection.LoggedIn True) Then MsgBox "QC User Authentication Failed" End End If 'Login to your Domain and Project QCConnection.Connect sDomain, sProject 'Quit if login fails to specified Domain and Project If (QCConnection.AuthenticationToken = "") Then MsgBox "QC Project Failed to Connect to " & sProject QCConnection.Disconnect End End If