I recently encountered an issue again while using Excel 2016 and VBA to add new items to a SharePoint list for job tracking. After installing Excel and seemingly setting everything up correctly, I ran into an error message when I tried to execute my code.
找不到可安裝的 ISAM。
Upon pressing Debug, I discovered that the error occurred at the .Open line of my connection string. This is a common issue I’ve faced before, and I often forget how to resolve it. So, I decided to document my experience to help myself—and others—next time we encounter this error.
Here’s my VBA code for reference:
' Sub AddItem(i As Integer)
Dim cnt As ADODB.Connection
Dim rst As ADODB.Recordset
Dim mySQL As String
Set cnt = New ADODB.Connection
Set rst = New ADODB.Recordset
mySQL = "SELECT * FROM [Your SharePoint List Name];"
With cnt ' See https://www.connectionstrings.com/sharepoint/
.ConnectionString = _
"Provider=Microsoft.ACE.OLEDB.12.0;WSS;IMEX=0;RetrieveIds=Yes;DATABASE=https://yoursharepointsite.sharepoint.com/sites/ABC/;LIST={xxxx-xxxx-xxxx-xxxx-xxx...};"
.Open
End With
rst.Open mySQL, cnt, adOpenDynamic, adLockOptimistic
rst.AddNew
rst.Fields("完成日期") = Date
rst.Fields("BU") = Trim(Cells(i, 1).Value)
rst.Fields("Project") = Trim(Cells(i, 2).Value)
rst.Fields("料號") = Trim(Cells(i, 3).Value)
rst.Fields("BOMRevision") = Trim(Cells(i, 4).Value)
rst.Fields("PCBRevision") = Trim(Cells(i, 5).Value)
rst.Fields("FTP_Path") = Cells(i, 15).Value
rst.Fields("File_Size") = Cells(i, 9).Value
rst.Update ' commit changes to SP list
If CBool(rst.State And adStateOpen) = True Then rst.Close
If CBool(cnt.State And adStateOpen) = True Then cnt.Close
MsgBox "請確認是否正常寫進M365 Sharepoint內的清單中~"
End Sub
But first, make sure you have activated the necessary object library references. If you’re experiencing errors related to ADODB connections or ODBC connectors, my solution might help.
Solution:
Download the Microsoft Access Database Engine 2016 Redistributable and install the version that matches your Office installation (32-bit or 64-bit).
Microsoft Access Database Engine 2016 可轉散發套件
This has resolved my connection issues almost every time.
如果我的文章對您有幫助, 您可以隨喜贊助哦! 感謝您。
