VBA ADODB Excel crashing on setting connection to nothing

JK2020 1 Reputation point Microsoft Employee
2022-05-30T21:36:49.637+00:00

Hello,

Following a recent Office update, the below code started crashing Excel for me.

Sub testSPConnection()
    Const spURL  As String = "https://myDomainName.sharepoint.com/teams/myTeamSite/"
    Const listID As String = "{5AB60906-62E5-418A-96A8-05A2E15V97X0}"
    Dim cn As Object

    Set cn = CreateObject("ADODB.Connection")
    With cn
        .ConnectionString = "Provider=Microsoft.ACE.OLEDB.12.0;WSS;IMEX=1;RetrieveIds=Yes;DATABASE=" & spURL & ";LIST=" & listID & ";"
        .Open
        'do something
        .Close
    End With
    Set cn = Nothing 'Excel crashes either here or, if this line is skipped, on End Sub
End Sub

Same when I run it in Word or Access.
I believe it might be to do with the .dll libraries, but not sure how to fix this.
Any ideas?

Microsoft 365 and Office SharePoint For business Windows
Developer technologies Visual Basic for Applications
{count} votes

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.