VBA 函数连接access以及excel,同时自动版本
Posted joewancn
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了VBA 函数连接access以及excel,同时自动版本相关的知识,希望对你有一定的参考价值。
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,同时自动版本的主要内容,如果未能解决你的问题,请参考以下文章
从 Access 2010 VBA 打开 Excel 2010 文件