Search code examples
excelado

Why Excel ADO cannot connect to a file


I am using Excel 2010 on Windows-11.

My problem is; the below simple ADO code returns an error saying that;

"Method 'Properties' of object '_Connection' failed

on line "adoCN.Properties("Data Source") = myFile"

The file is located in C:\TestFolder.

Sub Test()
    'Haluk - 19/07/2023
    
    Dim adoCN As Object, RS As Object
    Dim myFile As String, strSQL As String
    
    myFile = ThisWorkbook.FullName
    
    Set adoCN = CreateObject("ADODB.Connection")
    Set RS = CreateObject("ADODB.Recordset")
    
    adoCN.Provider = "Microsoft.ACE.OLEDB.12.0"
    adoCN.Properties("Data Source") = myFile
    adoCN.Properties("Extended Properties") = "Excel 12.0 Macro; HDR=Yes; IMEX=1"
    adoCN.Open
    
    strSQL = "Select * From [Sheet1$]"
    
    RS.Open strSQL, adoCN
    
    Sheets("Sheet2").Range("A2").CopyFromRecordset RS
    
    Set RS = Nothing
    Set adoCN = Nothing
End Sub

Also none of the ADO related VBA codes are not working which were working on Excel 2010 / Windows-7

I guess something is going wrong with Win11


Solution

  • Problem is solved after uninstalling and reinstalling Office 2010.