Vbscript如何读入Excel数据?

刚刚接触vb的菜鸟,求教,谢谢!
例如下面代码:
Sub Test1
Dim ng
Dim loginForm
Dim edit
Dim mainForm
Dim driver

TestedApps.TestedApp.Run
'输入密码
Set driver = DDT.ExcelDriver("c:\TB.xls","sheet1")
Set ngcrm = Aliases.ng
Set loginForm = ng.LoginForm
Set edit = Aliases.ng.LoginForm.Panel1.EdtPasswd
Call edit.Click(44, 7)
edit.wText = "zzw456!@#"

如果我想在edit.wText = "zzw456!@#"处读取excel的数据,代码要如何编写?

智慧大石
浏览 445回答 3
3回答

慕少森

vbs读取excel脚本倒是好说,但你的程序明显在vb与vba之间,恕我看不懂。 给你个例子参考下:' Read an Excel SpreadsheetSet objExcel = CreateObject("Excel.Application")Set objWorkbook = objExcel.Workbooks.Open _("C:\Scripts\New_users.xls")intRow = 2Do Until objExcel.Cells(intRow,1).Value = ""Wscript.Echo "CN: " & objExcel.Cells(intRow, 1).ValueWscript.Echo "sAMAccountName: " & objExcel.Cells(intRow, 2).ValueWscript.Echo "GivenName: " & objExcel.Cells(intRow, 3).ValueWscript.Echo "LastName: " & objExcel.Cells(intRow, 4).ValueintRow = intRow + 1LoopobjExcel.Quit

交互式爱情

<%set conn=Server.CreateObject("Adodb.Connection")Driver = "Driver={Microsoft&nbsp;Excel&nbsp;Driver (*.xls, *.xlsx, *.xlsm, *.xlsb)};"DBPath = "DBQ=" & Server.MapPath("zhenhe.xls") 'zhenhe.xls改为你的文件名conn.open Driver&DBPathsql="select * from [Sheet1$]" '[Sheet1$]表单名set rs=conn.execute(sql)for i=0 to Rs.Fields.Count-1response.write rs(i).name&""abcde=rs(0).name&""nextresponse.write "<br>"response.write "<br>"do while not rs.eoffor i=0 to Rs.Fields.Count-1response.write rs(i).value&""nextresponse.write "<br>"rs.movenextlooprs.closeset rs=nothingconn.closeset conn=nothing%><%=abcde%>&nbsp;
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

JavaScript