QCadmin,
Below is a template that I use often. This would require the QC Connectivity Add-in installed on the local machine in order for Excel to have the access to the libraries. You should be able to adjust the variables and go. You can add more columns by adding more rows under the ''Write the values to the worksheet'' section (be sure to increment the column letters).
Sub Query()
Dim qcServer, qcDomain, qcProject, qcUser, qcPassword, sSql
qcServer = ''http://qc:8080/qcbin/''
qcDomain = ''DEFAULT''
qcProject = ''QualityCenter_Demo''
qcUser = ''alex_qc''
qcPassword = ''''
Set tdc = CreateObject(''tdapiole80.tdconnection'')
'Check to see that the tdc object exists
If tdc Is Nothing Then
MsgBox ''The tdc object is empty''
End If
'Establish the connection and log in
tdc.InitConnectionEx qcServer
tdc.Login qcUser, qcPassword
tdc.Connect qcDomain, qcProject
'Create the tdc Command Object
Set oCommand = tdc.Command
'Build the query
sSql = ''SELECT REQ.RQ_REQ_ID As 'ReqID', '' & _
''REQ.RQ_REQ_NAME As 'Req Name' '' & _
''FROM REQ ''
'Set the SQL command to the Test Coverage query
oCommand.CommandText = sSql
'Execute the query and store in the SQLResults resultset.
Set SQLResults = oCommand.Execute
'Prepare the worksheet
Worksheets(''Sheet1'').Range(''A:B'').ClearContents
'Set the header row titles.
Worksheets(''Sheet1'').Range(''A1'') = ''Requirement ID''
Worksheets(''Sheet1'').Range(''B1'') = ''Requirement Name''
'Start populating data on row 2 (leaving the header information above).
iExcelRow = 2
'Iterate through the query results and populate the worksheet.
For iRecord = 1 To SQLResults.RecordCount
'Write the values to the worksheet
Worksheets(''Sheet1'').Range(''A'' & iExcelRow) = SQLResults.FieldValue(''ReqID'')
Worksheets(''Sheet1'').Range(''B'' & iExcelRow) = SQLResults.FieldValue(''Req Name'')
'Increment the iteration
iExcelRow = iExcelRow + 1
SQLResults.Next
Next
'Disconnect from Quality Center
If tdc.Connected = True Then
tdc.Disconnect
End If
'Log off the server
If tdc.LoggedIn Then
tdc.Logout
End If
'Release the TDConnection object.
tdc.ReleaseConnection
'Adjust the column width
Worksheets(''Sheet1'').Columns(''A:B'').EntireColumn.AutoFit
Set SQLResults = Nothing
Set oCommand = Nothing
Set tdc = Nothing
MsgBox ''Done''
End Sub