Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Open and read XLSX file

Status
Not open for further replies.

cumap

IS-IT--Management
Jul 9, 2007
268
US
Hello, I just cannot get this error out of the way:
Operation is not allowed when the object is closed.

And here is my code:
Code:
ConnStr = "Driver={Microsoft Excel Driver (*.xls)};" & _
           "DriverId=790;" & _
           "Dbq="&Server.MapPath("/excel/Book1.xlsx") & _
           "DefaultDir=c:\somepath" 
On Error Resume Next
Set objConn = Server.CreateObject("ADODB.Connection")
objConn.mode = 3 ' adModeReadWrite
objConn.Open ConnStr

if err.Number <> 0 then
	TrapError Err.Description
	Error.Clear
end if
on error goto 0

sql = "SELECT * FROM [Sheet1]"
set rs = objConn.Execute(sql)
if not rs.eof then
	testField = rs.getRows()
end if
rs.close
set rs=nothing
objConn.close
set objConn = nothing

The error points at this line: set rs = objConn.Execute(sql)
 
Please ignore the little error in ConnStr since I replace DefaultDir with Server.MapPath("/excel/"), still the same error persists.
 
add:
set rs = Server.CreateObject("ADODB.recordset")

and replace:
set rs = objConn.Execute(sql)

with:
rs.Open sql, objConn


?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top