I am trying to open an Excel sheet using ADODB connection, but I am getting the following error when I try to execute the query although the name of the worksheet is correct:
Error number: 3704
Error Description:Operation is not allowed when the object is closed
I have gone through most of the answers provided online and I still can find my answer as I already have what was missing in the answers I read.
Here is my code:
Dim objConn
Set objConn = Server.CreateObject("ADODB.Connection")
Dim ext : ext = GetFileExt(filename)
If ext = "xlsx" Then
With objConn
.Provider = "Microsoft.ACE.OLEDB.12.0"
.ConnectionString = _
"Data Source=" & Server.MapPath("../import/" & filename) & ";" & _
"Extended Properties=Excel 12.0;"
.CursorLocation = adUseClient
.Open
End With
End If
Dim sql
sql = "SELECT * FROM [" & worksheet & "$]"
Dim objRs
Set objRs = objConn.Execute(sql)
response.write "err.number: " & Err.Number '3704
response.write "err.Description: " & Err.Description 'Operation is not allowed when the object is closed