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
原文地址:https://www.cnblogs.com/joewancn/p/9898686.html
时间: 2024-11-01 13:24:40