我正在尝试使用ADODB连接打开Excel工作表,但是尽管工作表的名称正确,但是当我尝试执行查询时却遇到以下错误:
错误号:3704
错误描述:关闭对象后不允许操作
我已经遍历了在线提供的大多数答案,但是由于我已经阅读了答案中缺少的内容,因此我仍然可以找到答案。
这是我的代码:
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