Wrox Home  
Search P2P Archive for: Go

  Return to Index  

asp_web_howto thread: Excel problem


Message #1 by "Drew, Ron" <RDrew@B...> on Mon, 3 Jun 2002 10:43:41 -0400
Can anyone tell me what I am doing wrong???  I am getting this error the
file does not exist in the path on 47, no other program has it open..
Error Type:
Microsoft Excel (0x800A03EC)
Microsoft Excel cannot access the file
'C:\InetPub\wwwroot\asptest\test'. There are several possible reasons: *
The file name or path name does not exist. * The file you're trying to
open is being used by another program. Close the document in the other
program, and try again. * The name of the workbook you're trying to save
is the same as the name of another document that is read-only. Try
saving the workbook with a different name.
/asptest/test/excel1.asp, line 47

<%
'Set up Excel file
Dim row, col, Conn, Rs, Sql
row=3D2
col=3D5

' Open Database, retreive recordset
strQuery =3D Request.Form("strQuery")
Dim mdbPath, xlsConn, xlsPath, tblXLS
Set Conn =3D Server.CreateObject("ADODB.Connection")
mdbPath =3D Server.MapPath("test.mdb")
Conn.Open "Provider=3DMicrosoft.Jet.OLEDB.4.0;" & _
          "Data Source=3D" & mdbPath & ";" & _
          "User Id=3Dadmin;" & _
          "Password=3D;"     
Set Rs =3D Server.CreateObject("ADODB.Recordset")
Sql =3D "SELECT * " _
	& "FROM testname"
Set Rs =3D Conn.Execute(Sql)

Dim xlapp, xlsheet1
'set Excel objects
set xlapp =3D Server.CreateObject("Excel.Application")
set xlsheet1 =3D Server.CreateObject("Excel.sheet")
'Populate Column headers
	xlsheet1.ActiveSheet.Cells(row,1).Value =3D "ID"
	xlsheet1.ActiveSheet.Cells(row,2).Value =3D "Name"
	xlsheet1.ActiveSheet.Cells(row,3).Value =3D "City"
	xlsheet1.ActiveSheet.Cells(row,4).Value =3D "State"
	xlsheet1.ActiveSheet.Cells(row,5).Value =3D "Zip"
Rs.MoveFirst
while not Rs.EOF
	'populate cells
	row =3D row+1
	xlsheet1.ActiveSheet.Cells(row,1).Value =3D Rs("ID")
	xlsheet1.ActiveSheet.Cells(row,2).Value =3D Rs("Name")
	xlsheet1.ActiveSheet.Cells(row,3).Value =3D Rs("City")
	xlsheet1.ActiveSheet.Cells(row,4).Value =3D Rs("State")
	xlsheet1.ActiveSheet.Cells(row,5).Value =3D Rs("Zip")
	Rs.MoveNext
wend

'Save spreadsheet to server
xlsheet1.ActiveSheet.Cells.Select
xlsheet1.ActiveSheet.Cells.EntireColumn.Autofit
xlapp.application.DisplayAlerts =3D false
xlsheet1.SaveAs "C:/InetPub/wwwroot/asptest/test/testname.xls"      '<<<
line 47
'close and release objects
xlapp.quit
Set xlsheet1 =3D nothing
set xlapp =3D nothing
RS.Close
Conn.Close
set RS =3D nothing
set Conn =3D nothing
' Open spreadsheet automatically
Response.Redirect ("excel/testname.xls")
%>

  Return to Index