Code:
Sub Report(URL, Usr, Pwd, Dom, Prj, Sql)
Set TDConnection = CreateObject("TDApiOle80.TDConnection")
TDConnection.InitConnectionEx URL
TDConnection.Login Usr, Pwd
TDConnection.Connect Dom, Prj
Set Com = TDConnection.Command
Com.CommandText = Sql
Set RecSet = Com.Execute
For Col = 1 To RecSet.ColCount
Cells(1, Col).Value = RecSet.ColName(Col - 1)
Next
Row = 1
Do While Not RecSet.EOR
Row = Row + 1
For Col = 1 To RecSet.ColCount
Cells(Row, Col) = RecSet.FieldValue(Col - 1)
Next
RecSet.Next
Loop
TDConnection.Disconnect
TDConnection.Logout
TDConnection.ReleaseConnection
End Sub