|
'创建excel的对象
Set ExcelObj = CreateObject("Excel.Application")
'指定一个execl的格式,这个需要我们事先定制好
aatype="c:\Global.xls"
'打开excel
ExcelObj.Workbooks.Open(aatype)
'设置操作的工作表
Set NewSheet = ExcelObj.Sheets.Item(2)
'以下是数据库操作
Dim rs,sq,pkey
'set conn=createobject("adodb.command")
set conn=createobject("adodb.connection")
set rs=createobject("adodb.recordset")
set rs1=createobject("adodb.recordset")
'conn.activeconnection="DRIVER=SQL Server;SERVER=10.10.40.61;DATABASE=CUL;user id=sa ; password=sa"
conn.open="DRIVER=SQL Server;SERVER=10.10.40.61;DATABASE=CUL;user id=sa ; password=sa"
sql="select * from TDoc"
rs.open sql,conn
i=1
do while not rs.eof
values1=rs("pkey")
values2=rs("name")
NewSheet.Cells(i+1,1).Value =values1
NewSheet.Cells(i+1,2).Value =values2
i=i+1
rs.movenext
Loop
'保存excel数据
ExcelObj.ActiveWorkbook.Saveas "C:\data.xls"
ExcelObj.Quit
Set ExcelObj = Nothing
rs.close
set rs=nothing
conn.close
set conn=nothing
大家讨论下这个脚本我怎么运行不成功的啊?请教达人,出现的错误如下:
file:///C:/Documents%20and%20Settings/Administrator/桌面/图片.png |
|