'从excel表里读取数据的简单例子
'$include "sqautil.sbh" '头包含
Sub Main
Dim Result As Integer
dim excel as Object '定义对象
dim book as Object
dim worksheet as Object
dim name1 as String
dim pass as String
dim count as Integer
on error resume next
Set excel = GetObject("excel.application") '设置excel变量为execl对象
if(excel Is Nothing) then '判断是否设置成功
Set excel = CreateObject("excel.application") '创建excel对象
if(excel Is Nothing) then '判断是否创建成功
MsgBox "Couldn't find Excel!"
Exit Sub
End if
End if
Set book = excel.Workbooks.Open("d:\qingd.xls") '打开具体Excel文件,这里是我d盘下一个名为qingd的xls文件
Set worksheet = book.Worksheets("1") '设置工作的表,工作表的名字为1
For count=1 To 3 '在excel表里取三行数据
name1 = worksheet.Cells(count,1).Value '从表中取具体行列对应的值
'pass = worksheet.Cells(2,1).Value
msgbox name1
next count
excel.Quit '关闭excel
Set excel = Nothing '把excel对象设置为空
End Sub
--------------------next---------------------
阅读(428) | 评论(0) | 转发(0) |