![]() |
【转帖】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. |