02-16-2011, 03:47 PM
Hi,
Use this below code to get the records and save it in excel file
Use this below code to get the records and save it in excel file
Code:
var_Schema="QADB"
SchemaUserNme="GHA09"
SchemaPswd="GHA09"
Set conn=CreateObject("ADODB.Connection")
Set Rec=CreateObject("ADODB.Recordset")
Set obj=CreateObject("Excel.Application")
Set wrk=obj.Workbooks.Open("C:\Book1.xls")
conn.open "Driver={Microsoft ODBC for Oracle};Server="&var_Schema&";UID="&SchemaUserNme&";Password="&SchemaPswd&";"
SQL="Select * from user_mas where role_id='FC'"
Rec.Open SQL,conn
R=1
Do until Rec.EOF
var1=Rec.Fields ("User_id")
Rec.MoveNext
obj.Sheets(1).Cells(R,1).value=var1
'obj.Sheets(1).Cells(rowcount, 1).Value = var_user_id
R=R+1
Loop
Rec.Close
Set Rec=Nothing
conn.Close
Set conn=Nothing
obj.Application.activeworkbook.Save
obj.Application.activeworkbook.Close
obj.Application.Quit
Set wrk=Nothing
Set obj=Nothing