几何尺寸与公差论坛------致力于产品几何量公差标准GD&T (GDT:ASME)|New GPS(ISO)研究/CAD设计/CAM加工/CMM测量

几何尺寸与公差论坛------致力于产品几何量公差标准GD&T (GDT:ASME)|New GPS(ISO)研究/CAD设计/CAM加工/CMM测量 (http://www.dimcax.com/hust/index.php)
-   数据库ObjectDBX (http://www.dimcax.com/hust/forumdisplay.php?f=177)
-   -   【转帖】vba连接excel数据库(非引用excel) (http://www.dimcax.com/hust/showthread.php?t=8423)

yang686526 2009-04-19 04:39 PM

【转帖】vba连接excel数据库(非引用excel)
 
vba连接excel数据库(非引用excel)
www.dimcax.com
vba连接excel数据库(非引用excel)
public conn as new adodb.connection '定义新连接
public cmd as new adodb.command '定义指令
public rs as new adodb.recordset '定义两个记录集
'vba连接excel数据库
sub aa()
set conn = new connection
conn.open "provider=msdasql.1;dbq=d:\1.xls;driver={driver do microsoft excel(*.xls)};readonly=1"
set cmd.activeconnection = conn
cmd.commandtext = "select * from aa"
rs.cursorlocation = aduseclient
'为什么下边这行会出错,换成连接access时,同样的语法可以通过
rs.open cmd, , adopenstatic, adlockbatchoptimistic
dim num as integer
num = rs.fields.count
'声明动态数据,存储所有字段名
dim a()
dim n as integer
redim a(num - 1)
n = 0
for each red in rs.fields
a(n) = red.name
n = n + 1
next
cc = rs.getrows(, 2, "半径")
rs.close
end sub


所有的时间均为北京时间。 现在的时间是 11:57 AM.