I am trying to use ODBC to read a closed spreadsheet. The code that I am using (see below) works, but instead of just reading the data, it is actually opening the file and reading the data. I do not understand why or how. Any ideas would be greatly appreciated. Here is the code:
Public Function read_table(ByVal sSearchVal As String) As String
Dim sCurrDir As String
Dim Conn As Connection
Dim adoConn As ADODB.Connection
Dim adoRS As ADODB.Recordset
Dim sTab As String
Dim sRange As String
sCurrDir = ThisWorkbook.Path
If InStr(sCurrDir, scDevmnt) > 0 Then
sCurrDir = scDevTbl
Else
sCurrDir = scProdTbl
End If
sTab = "User Area 5"
sRange = "A1:B6"
Set adoConn = New ADODB.Connection
adoConn.Open "DRIVER={Microsoft Excel Driver (*.xls)};ReadOnly=1;DBQ=" & sCurrDir
' adoConn.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & sCurrDir & ";Extended Properties=""Excel 8.0;HDR=NO;"""
Set adoRS = adoConn.Execute("SELECT TRANSLATION FROM [" & sTab & "$" & sRange & "] WHERE NBU='" & sSearchVal & "'")
If adoRS.EOF Then
read_table = sSearchVal
Else
read_table = adoRS.Fields(0)
End If
adoRS.Close
adoConn.Close
Set adoRS = Nothing
Set adoConn = Nothing
End Function
I let my mind wander ... it never came back!