设为首页收藏本站Access中国

Office中国论坛/Access中国论坛

 找回密码
 注册

QQ登录

只需一步,快速开始

返回列表 发新帖
查看: 1871|回复: 1
打印 上一主题 下一主题

[VBA编程/宏] Excel不引用DAO直接对Access数据库操作

[复制链接]

点击这里给我发消息

跳转到指定楼层
1#
发表于 2015-4-4 10:05:26 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
本帖最后由 盗梦 于 2015-4-4 10:07 编辑

一般Excel要读写Access数据库,需要引用DAO或ADO数据库操作组件以下方法 是不引用DAO对数据库操作 (摘录自网络)  

  1. Sub DaoWithoutReferences()       '定义变量.      
  2.     Dim dbEng As Object      
  3.    Dim Db As Object      
  4.    Dim Rs As Object       '使用OLE方式创建dbEngine对象。Set the dbEng object using OLE      
  5.    Set dbEng = CreateObject("DAO.DBEngine")      
  6.    'NOTE: In Microsoft Excel 97, use this line of code instead of the       'above line of code:       '      
  7.    '   Set dbEng = CreateObject("DAO.DBEngine.35")       '打开数据库 Open a database. Note that the statement contains the dbEng object.      
  8.      Set Db = _           
  9.         dbEng.workspaces(0).opendatabase("c:\MSOffice\Access" & _           
  10.          "Samples\Northwind.mdb")       '在数据库中打开记录信 Open a recordset in the database.      
  11.          Set Rs = Db.openrecordset("Customers")      
  12.          '获取数据库记录数 Perform a move last and find the number of records       'in the database to test if the operation worked.      
  13.           Rs.movelast      
  14.            MsgBox Rs.recordcount      
  15.           Set Rs = Nothing      
  16.          Set Db = Nothing      
  17.          Set dbEng = Nothing   
  18. End Sub               
复制代码


分享到:  QQ好友和群QQ好友和群 QQ空间QQ空间 腾讯微博腾讯微博 腾讯朋友腾讯朋友
收藏收藏1 分享分享 分享淘帖 订阅订阅
2#
发表于 2015-4-13 14:21:30 | 只看该作者
谢谢您的分享!
您需要登录后才可以回帖 登录 | 注册

本版积分规则

QQ|站长邮箱|小黑屋|手机版|Office中国/Access中国 ( 粤ICP备10043721号-1 )  

GMT+8, 2024-5-2 09:02 , Processed in 0.079161 second(s), 25 queries .

Powered by Discuz! X3.3

© 2001-2017 Comsenz Inc.

快速回复 返回顶部 返回列表