查看单个帖子
旧 2009-04-19, 04:39 PM   #1
yang686526
高级会员
 
注册日期: 06-11
帖子: 14579
精华: 1
现金: 224494 标准币
资产: 234494 标准币
yang686526 向着好的方向发展
默认 【转帖】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
yang686526离线中   回复时引用此帖
GDT自动化论坛(仅游客可见)