I'm trying to use vba in Excel (2013) to use ADODB connection and SQL to query and collate data from another tab. My laptop is running Windows 10 Pro 64-bit(10.0.17763) and Excel Standard 2013 64-bit (15.0.5233.1000)
I have tried removing and re-adding my Active X References, but has not solved the issue. I've also tried removing all possible references and re-adding them one by one as well as trying to use older versions. All result in the same result. My references chosen are: Visual Basic for Applications, Microsoft Excel 15.0 Object Library, OLE Automation, Microsoft Office 15.0 Object Library, Microsoft Forms 2.0 Object Library, Microsoft ActiveX Data Objects 6.1 Library, Microsoft ActiveX Data Objects Recordset 6.0 Library.
When I get to the cnExcel.Open in the below code, excel just crashes(i.e. closes) with no error messages.
Dim cnExcel As Connection
Dim rsExcel As Recordset
.....
strFile = ThisWorkbook.FullName
strCon = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=""C:\Users\trheinsc\Desktop\InProgress\Error Dashboard_TEMPLATE.xlsm"";Extended Properties=""Excel 12.0;HDR=Yes;IMEX=1"";"
Set cnExcel = CreateObject("ADODB.Connection")
Set rsExcel = CreateObject("ADODB.Recordset")
rsExcel.CursorLocation = adUseClient
cnExcel.Open strCon ' <= This is where Excel blows up and shuts down.
' Populate Iteration Columns
sqlSelect = "SELECT DISTINCT [Iteration]"
sqlFrom = "FROM [ErrorDetail$]"
sqlWhere = "WHERE [Iteration] Is Not NULL"
sqlGroup = ""
sqlOrder = "ORDER BY [Iteration] DESC"
sqlString = sqlSelect & " " & sqlFrom & " " & sqlWhere & " " & sqlGroup & " " & sqlOrder
rsExcel.Open sqlString, cnExcel
cDashRow = 1
cDashCol = FirstIterCol
Do
If rsExcel.EOF Then Exit Do
shDashboard.Cells(cDashRow, cDashCol) = "Iter " & rsExcel(0) & Chr(10) & "# Errors"
shDashboard.Cells(cDashRow, cDashCol).Columns.AutoFit
aIterArray(cDashCol) = rsExcel(0)
cDashCol = cDashCol + 1
rsExcel.MoveNext
Loop Until rsExcel.EOF
LastIterCol = cDashCol - 1
If rsExcel.State = 1 Then rsExcel.Close
Any assistance would be greatly appreciated.
"
around the data-source, only around the extended properties. Also the extended properties should readExcel 12.0 Xml;
if I'm not mistaken. – Kostas K.Excel 12.0 Marco
andExcel 12.0 Xml
. What's the drive behind this? Does it suppress the macros? I don't think so. – Kostas K.