各版本ExcelAdo连接代码
作者:admin 日期:2020-02-23
07~19版本ExcelAdo连接代码:
Sub test()
Dim cnn As Object
Set cnn = CreateObject("adodb.connection")
cnn.Open "provider=microsoft.ace.oledb.12.0;extended properties=excel 12.0;data source=" & ThisWorkbook.FullName
If cnn.State = 1 Then
MsgBox "连接成功!" & vbCrLf & "ADO版本为:" & cnn.Version & vbCrLf & "Connection对象提供者名称:" & cnn.provider
cnn.Close
Set cnn = Nothing
Else
MsgBox "数据库连接失败"
End If
End Sub
来源:https://mp.weixin.qq.com/s?__biz=MzI0MTAxNTc5NA==&mid=2468634602&idx=4&sn=4a53cea4ba4a85ae828b17a8f42f693e&chksm=ffc2f177c8b578618aee2e7408bac59c76470c9211969933e3617f91e5e79373d469eebf7927&scene=21#wechat_redirect以下代码兼顾了03及各高级版本Excel的情况:Sub Mycnn3()Dim cnn As ObjectDim strPath As StringDim str_cnn As StringSet cnn = CreateObject("adodb.connection")strPath = ThisWorkbook.FullNameIf Application.Version < 12 Thenstr_cnn = "Provider=Microsoft.jet.OLEDB.4.0;Extended Properties=Excel 8.0;Data Source=" & strPathElsestr_cnn = "Provider=Microsoft.ACE.OLEDB.12.0;Extended Properties=Excel 12.0;Data Source=" & strPathEnd Ifcnn.Open str_cnncnn.CloseSet cnn = NothingEnd sub来源:https://mp.weixin.qq.com/s?__biz=MzI0MTAxNTc5NA==&mid=2468634477&idx=3&sn=47e652209bab466e8bab3e27cd38a58d&chksm=ffc2f1f0c8b578e6e7ea0fac79289ff858e82641dd740e45e3135644a895fd74a550061bdf99&scene=21#wechat_redirect
[本日志由 admin 于 2020-02-23 05:53 PM 更新]
上一篇: 学SQL in Excel教程合集下一篇: 在excel中引用ADO类库的两种方法
文章来自: 本站原创
引用通告: 查看所有引用 | 我要引用此文章
Tags:
相关日志:
评论: 0 | 引用: 0 | 查看次数: 2336
发表评论
扫码领红包!领到大红包的小伙伴赶紧使用哦!