我正在尝试对我的Excel工作簿使用SQL查询,但我无法打开连接。它在带有未指定错误运行时错误'-2147467259(80004005)'的cn.Open strCon行上失败。
Function Test()
Dim cn As Object 'ADODB.Connection
Dim rs As Object 'ADODB.Recordset
Dim currAddress As String
Dim strSQL As String
Dim strCon As String
strFile = ThisWorkbook.FullName
strCon = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" & strFile & ";Extended Properties=""Excel 12.0;HDR=Yes;IMEX=1"";"
Set cn = CreateObject("ADODB.Connection")
Set rs = CreateObject("ADODB.Recordset")
cn.Open strCon
strSQL = "SELECT * FROM AdelPivot"
rs.Open strSQL, cn
Sql = rs.GetString
End Function