|
是套用别人代码来着,一样的代码放别人的QTP里执行没错,放我这里就报错了,而且报了六个错,Look:
我到底犯了什么愚蠢的错误呢?我用的是QTP9.2,谢谢了啊。红色的是报错的地方。
Set excelObj = CreateObject("Excel.Application") '创建一个对象
xlsUrl = "Z:\1.xlsx" '指定一个已经存在的XSL文件路径
excelObj.workbooks.open(xlsUrl) '打开EXCEL
Set sheetNew = excelObj.sheets.item(1) '设置将数据放在EXCEL中的那一页上(索引从1开始)
'相关的数据库操作
Dim conn,rs,sql,conset
Set conn = CreateObject("adodb.connection")
set rs = createobject("adodb.recordset")
conset = "DRIVER={Microsoft Access Driver (*.mdb)};DBQ=C:\Program Files\Mercury Interactive\QuickTest Professional\samples\flight\app\flight32.mdb"
conn.open conset
sql="select * from orders"
rs.open sql,conn
Dim i
while not rs.eof
Value1 = rs("Order_Number").value
Value2 = rs("Customer_Name").value
sheetNew.cells(i+1,1).value = Value1 '列付值
sheetNew.cells(i+1,2).value = Value2 '列付值
i = i + 1
rs.movenext
Wend
excelObj.activeworkbook.saveas "Z:\1.xlsx" '保存数据
excelObj.quit '关闭对象
set excelObj = nothing '清空对象
rs.close '关闭数据库连接操作
set rs=nothing
conn.close
set conn = nothing |
|