在VBA excel中设置与access数据库的连接
这是我用来从excel打开到access数据库的连接的代码。它过去工作了一年多在VBA excel中设置与access数据库的连接,vba,excel,crash,adodb,Vba,Excel,Crash,Adodb,这是我用来从excel打开到access数据库的连接的代码。它过去工作了一年多 Set dbname = New ADODB.Connection theconnection = "//xxx.sharepoint.com/sites" & Application.PathSeparator & TARGET_DB With dbname .Provider = "Microsoft.ACE.OLEDB.12.0" .Open theconnection End
Set dbname = New ADODB.Connection
theconnection = "//xxx.sharepoint.com/sites" & Application.PathSeparator & TARGET_DB
With dbname
.Provider = "Microsoft.ACE.OLEDB.12.0"
.Open theconnection
End With
通过尝试一个错误,我得出结论,这条线是造成问题的原因
Set dbname= New ADODB.Connection
问题是在我的电脑自动更新后出现的
我的Excel版本2016 MSO(16.0.7726.1036)32位
请告诉我您是否也遇到过此问题,以及是否知道任何修复或解决方法。也许吧
Dim dbname As Object
Set dbname = CreateObject("ADODB.Connection")
theconnection = "//xxx.sharepoint.com/sites" & Application.PathSeparator & TARGET_DB
With dbname
.Provider = "Microsoft.ACE.OLEDB.12.0"
.Open theconnection
End With
我用的都是这样的代码
Dim Rs As Object
Dim strConn As String
Dim i As Integer
Dim strSQL As String
strSQL = "select * from [table] "
strConn = "Provider=Microsoft.ACE.OLEDB.12.0;" & _
"Data Source=" & ThisWorkbook.FullName & ";" & _
"Extended Properties=Excel 12.0;"
Set Rs = CreateObject("ADODB.Recordset")
Rs.Open strSQL, strConn
If Not Rs.EOF Then
With Ws
.Range("a1").CurrentRegion.ClearContents
For i = 0 To Rs.Fields.Count - 1
.Cells(1, i + 1).Value = Rs.Fields(i).Name
Next
.Range("a" & 2).CopyFromRecordset Rs
End With
End If
Rs.Close
Set Rs = Nothing
- 尝试取消选中“ActiveX数据对象”引用并将其添加回:
- 使用对象定义数据库:
Dim dbname As Object Set dbname = CreateObject("ADODB.Connection")
Dim con as New ADODB.Connection
将其更改为:
Dim con as ADODB.Connection
Set con = New ADODB.Connection
谢谢你的提示。问题解决了。当我检查引用时,我检查了MicrosoftActiveX数据对象6.0库。当我检查它时,它消失了。看起来在某些office 365升级过程中,它被更改为6.1版。当我检查这个版本时,它又开始工作了。再次感谢您的帮助。我尝试了这个,但没有解决问题。是Microsoft ActiveX库升级导致了此问题。谢谢你的帮助。@MarcinDramiński:我修改了我的答案,完整的代码。