码迷,mamicode.com
首页 > 数据库 > 详细

VBA 函数连接access以及excel,同时自动版本

时间:2018-11-02 23:43:37      阅读:268      评论:0      收藏:0      [点我收藏+]

标签:函数   cat   nec   ext   join   ros   val   func   record   

Private Function AccessJoinString() As String
If Val(Application.Version) < 12 Then
AccessJoinString = "Microsoft.Jet.Oledb.4.0"
Else
AccessJoinString = "Microsoft.Ace.Oledb.12.0"
End If
End Function


Private Function ExcelJoinString() As String
If Val(Application.Version) < 12 Then
ExcelJoinString = "Microsoft.Jet.Oledb.4.0;Extended Properties=Excel 8.0"
Else
ExcelJoinString = "Microsoft.Ace.Oledb.12.0;Extended Properties=Excel 12.0"
End If
End Function
Function AccessExecuteRecordset(AccessPath As String, sql As String) As Object
Dim cn As Object, rs As Object
Set cn = CreateObject("Adodb.Connection")
With cn
.Provider = AccessJoinString
.Open AccessPath
End With
Set rs = cn.Execute(sql)
Set AccessExecuteRecordset = rs
End Function

Function ExcelExecuteRecordset(ExcelPath As String, sql As String) As Object
Dim cn As Object, rs As Object
Set cn = CreateObject("Adodb.Connection")
With cn
.Provider = ExcelJoinString
.Open ExcelPath
End With
Set rs = cn.Execute(sql)
Set ExcelExecuteRecordset = rs
End Function

 

  

VBA 函数连接access以及excel,同时自动版本

标签:函数   cat   nec   ext   join   ros   val   func   record   

原文地址:https://www.cnblogs.com/joewancn/p/9898686.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!