Dim oExcel
'根据列名返回列号
function getcol(fieldname)
Dim fieldno
fieldno=1
do while not oExcel.Cells(1,fieldno).Value=""
If fieldname=oExcel.Cells(1,fieldno).Value Then
getcol=fieldno
Exit do
End If
fieldno=fieldno+1
loop
End function
'配置需要的excel对象
Function setfileandsheet(filename,sheetname)
set oExcel = CreateObject( "Excel.Application" )
oExcel.WorkBooks.Open( filename )
oExcel.WorkSheets(sheetname).Activate
oExcel.Visible = True
End Function
oExcel.WorkBooks.Close
End Function
'根据列名和行号读取数据
Function Sgetdate(rowno,colname)
fieldno=getcol(colname)
Sgetdate=oExcel.Cells(rowno,fieldno).Value
End Function
Do
WScript.Sleep 1000
Loop Until CInt(obj.readyState)=4
End Sub
'以下是一个例子。直接请求google搜索某一个关键字。弹出显示response中的搜索框的内容
Dim rowno
'从第二行开始读数据,因为第一行是列名
rowno=2
Set aaa=new SDateSheet
'载入参数化文件并制定sheet
call aaa.setfileandsheet("E:\vbsscripttest\test.xls",1)
Set ie = CreateObject("internetexplorer.application")
ie.Visible = true
While not aaa.oExcel.Cells(rowno,1).Value=""
ie.Navigate "http://www.google.cn/search?hl=zh-CN&newwindow=1&q=" & aaa.Sgetdate(rowno,"name") & "&aq=f&oq="
set qset=ie.document.getElementsByName("q")
msgbox qset(0).value
Call aaa.closeexl
Set aaa=nothing
Set ie=nothing
name | gander |
sunmx | male |
yemn | male |
vicky | female |