您的位置:程序门 -> vb -> vba



求vb中与excel表连接,从excel表中读数据


[收藏此页] [打印本页]选择字色:背景色:字体:[][][]


求vb中与excel表连接,从excel表中读数据
发表于:2007-10-29 11:28:14 楼主
求vb中与excel表连接,从excel表中读数据,数据在excel中是矩阵的形式,在vb中是二维数组。高手们帮帮忙吧
发表于:2007-10-29 11:46:381楼 得分:0
vbscript code
option explicit dim ex as excel.application dim wb as excel.workbook dim sh as excel.worksheet private sub form_load() on error goto err1 set ex = new excel.application set wb = ex.workbooks.open("c:\documents and settings\yong.zzy\桌面\book1.xls") set sh = wb.sheets(1) debug.print sh.name dim arr(1, 1) dim i as integer, j as integer for i = 1 to 2 for j = 1 to 2 arr(i - 1, j - 1) = sh.cells(i, j).value debug.print arr(i - 1, j - 1) next j next i exit sub err1: set sh = nothing set wb = nothing set ex = nothing debug.print err.description end sub private sub form_unload(cancel as integer) set sh = nothing set wb = nothing set ex = nothing end sub
发表于:2007-10-29 11:52:092楼 得分:0
忘了关闭了
wb.close
ex.quit
发表于:2007-10-29 14:56:333楼 得分:0
[code=vb]
        dim   strfilename   as   string
        strfilename   =   getexcelfilename("客户资料表",   dlg)
       
        dim   objapp   as   new   excel.application
        dim   exbook   as   excel.workbook
        dim   exsheet   as   excel.worksheet
       
        set   exbook   =   objapp.workbooks.open(strfilename)
        set   exsheet   =   exbook.worksheets(1)
        //存放在varcustomerlist中
        dim   varcustomerlist   as   variant
       
        varcustomerlist   =   exsheet.usedrange.value


[/code]
发表于:2007-10-31 11:14:594楼 得分:0
发表于:2007-10-31 12:37:535楼 得分:0
http://blog.csdn.net/vbman2003/archive/2007/10/25/1843645.aspx


快速检索

最新资讯
热门点击