I am trying to query an Excel file from another file using VBA and ADO options. When I run this code it's throwing the error "Cannot updata, Database or object Read only":
Public Function fnExecuteXlQuery _
(ByVal strPath As String, _
ByVal strQuery As String) As ADODB.Recordset
Dim rs As ADODB.Recordset
Dim conStr As String
On Error GoTo ErrorHandler
conStr = "Provider=Microsoft.Jet.OLEDB.4.0; " _
& "Data Source=" & strPath & "; Extended Properties=Excel 8.0"
Set rs = New ADODB.Recordset
rs.Open strQuery, conStr, adOpenDynamic
Set fnExecuteXlQuery = rs
Exit Function
ErrorHandler:
Set fnExecuteXlQuery = Nothing
fnDisplayError Error(Err) & "Unable to fetch data from DTS...", ERROR_TYPE_ERROR
End Function
The "strPath" is the source Excel file and the "strquery" has the following SQL code:
Select [Activity],[Name],[Date],[Hours Spent]
from [Time sheet$]
where [Activity] = 'Billable Activities'
Order by Name,date